from plone.dexterity.content import Container
from plone.namedfile.interfaces import IImageScaleTraversable
from plone.supermodel import model
from ploneintranet.attachments.attachments import IAttachmentStoragable
from ploneintranet.layout.app import AbstractAppContainer
from ploneintranet.layout.interfaces import IAppContainer
from ploneintranet.workspace.interfaces import IWorkspaceAppContentLayer
from ploneintranet.workspace.interfaces import IWorkspaceAppFormLayer
from zope.globalrequest import getRequest
from zope.interface import implementer


class IWorkspaceContainer(model.Schema, IImageScaleTraversable, IAppContainer):
    """
    Marker interface for WorkspaceContainer
    """


@implementer(IWorkspaceContainer, IAttachmentStoragable, IAppContainer)
class WorkspaceContainer(AbstractAppContainer, Container):
    """
    A folder to contain WorkspaceFolders.

    Implements IAppContainer to enable workspace-specific content view
    registrations.
    """

    app_name = "workspace"  # should not contain dots
    app_layers = (IWorkspaceAppContentLayer, IWorkspaceAppFormLayer)

    def _get_id(self, suggested_id):
        """Override the OFS.CopySupport.CopyContainer to return a proper id
        avoiding the need to rename workspace created from a template
        if a _copy_move_suggested_id parameter is set
        """
        request = getRequest() or {}
        suggested_id = request.get("_copy_move_suggested_id", suggested_id)
        return super()._get_id(suggested_id)
