from plone.app.contenttypes.interfaces import IFolder
from plone.namedfile.field import NamedBlobImage
from plone.namedfile.interfaces import IImageScaleTraversable
from plone.supermodel import model
from ploneintranet.core import _
from ploneintranet.layout import interfaces as ilayout
from ploneintranet.layout.interfaces import INoBarcelonetaLayer
from zope import schema
from zope.interface import Attribute
from zope.interface import Interface
from zope.interface.interfaces import IObjectEvent


class IPloneintranetWorkspaceLayer(Interface):
    """Zope 3 browser layer which is active regardless of themeswitching"""


class IThemedWorkspaceLayer(IPloneintranetWorkspaceLayer, INoBarcelonetaLayer):
    """Zope 3 browser layer which is *not* present in Barceloneta fallback"""


class IWorkspaceAppContentLayer(ilayout.IPloneintranetContentLayer, ilayout.IAppLayer):
    """Marker interface for content within a workspace app."""


class IWorkspaceAppFormLayer(ilayout.IPloneintranetFormLayer, ilayout.IAppLayer):
    """Marker interface for forms within a workspace app."""


class IParticipationPolicyChangedEvent(Interface):
    """Event, which is fired once the participation policy
    of the workspace has changed
    """

    old_policy = Attribute("Policy we are moving away from")
    new_policy = Attribute("Policy we are moving to")


class IWorkspaceRosterChangedEvent(Interface):
    """
    Event, which is fired once the roster of a workspace had changed
    """


class IWorkspaceCreatedFromTemplateEvent(Interface):
    """A workspace has been created by copying a template.
    This event allows us to disable the auditlog while the other events are
    fired and then create only one entry via this event. Otherwise all items
    contained in the template trigger audit entries when copied.
    """


class IObjectModifiedAfterCreationEvent(IObjectEvent):
    """Event which is fired in the special case where we set the fields of an
    object after first creating it empty.
    """


class ICaseManagerAware(Interface):
    """Marker interface for classes that are aware of the case manager app"""


class IBaseWorkspaceFolder(model.Schema, IImageScaleTraversable):
    """
    Interface for WorkspaceFolder
    """

    calendar_visible = schema.Bool(
        title=_(
            "label_workspace_calendar_visibility",
            "Calendar visible in central calendar",
        ),
        required=False,
        default=False,
    )
    division = schema.TextLine(
        title=_("label_workspace_division", "Belongs to this Division"),
        required=False,
        default="",
    )
    email = schema.TextLine(
        title=_("label_workspace_email", "E-mail address"),
        required=False,
        default="",
    )
    archival_date = schema.Datetime(
        title=_("label_archived", "Archived"), required=False, default=None
    )
    related_workspaces = schema.List(
        value_type=schema.ASCIILine(
            title=_("label_workspace_uid", "UID of a workspace"),
            required=False,
            default="",
        ),
        title=_("label_related_workspaces", "Related workspaces"),
        required=False,
        defaultFactory=list,
    )
    hero_image = NamedBlobImage(title=_("Hero Image"), required=False)
    infographic_image = NamedBlobImage(
        title=_("label_workspace_infographic", default="Workspace infographic"),
        required=False,
    )
    infographic_image_description = schema.Text(
        title=_("Workspace infographic description"),
        required=False,
        default="",
    )
    hotspots = schema.Dict(
        title=_("Hotspots"),
        key_type=schema.TextLine(),
        value_type=schema.TextLine(),
        required=False,
    )
    default_grouping = schema.TextLine(
        title=_("label_default_grouping", "Default grouping for this workspace"),
        required=False,
        default="",
    )
    remote_admin = schema.TextLine(title="Remote admin", required=False, default="")
    show_activity_stream = schema.Bool(
        title=_("label_show_activity_stream", "Show activity stream"),
        description=_(
            "help_show_activity_stream",
            "Show or hide the activity stream on the workspace landing page.",
        ),
        required=False,
        default=True,
    )
    stream_num_columns = schema.Int(
        title="Workspace landing page columns", required=False, default=1
    )


class IWorkspaceFolder(IBaseWorkspaceFolder):
    """A workspace folder can be a division,
    while other objects inheriting from IBaseWorkspaceFolder cannot,
    e.g. cases
    """

    is_division = schema.Bool(
        title=_(
            "label_workspace_is_division",
            "Is this workspace representing a division?",
        ),
        description=_(
            "Divisions represent sections of the overall "
            "organisation and appear "
            "as groupings on the workspace overview."
        ),
        required=False,
        default=False,
    )


class IMetroMap(Interface):
    """Methods required to display a metromap"""

    def metromap_sequence():
        """An ordered dict with the structure required for displaying tasks in
        the metromap and in the sidebar of a Case item. This is used to
        determine which states have been finished, and
        which transitions are currently available.
        OrderedDict([(
            "new", {
                "is_current": False,
                "transition_id": "transfer_to_department",
                "finished": True,
            }), (
            "in_progress", {
                "is_current": False,
                "transition_id": "transfer_to_department",
                "finished": True,
            }),
        ])
        """


class IGroupingStoragable(Interface):
    """marker interface for things that can have a GroupingStorage"""


class IGroupingStorage(Interface):
    def update_groupings(obj):
        """Update the groupings dict with the values stored on obj."""

    def remove_from_groupings(obj):
        """Remove obj's grouping relevant information to its workspace."""

    def reset_order():
        """Reset the order for all groupings to default, i.e. same order
        as the keys of the OOBTree
        """

    def get_order_for(grouping, include_archived=False, alphabetical=False):
        """Get order for a given grouping"""

    def set_order_for(grouping, order):
        """Set order for a given grouping"""

    def get_groupings():
        """Return groupings"""


class IMail(IFolder):
    """Marker interface for the ploneintranet.workspace.mail content type"""


class ITrashable(Interface):
    """Marker interface for objects that can be trashed"""


class ITrashed(ITrashable):
    """Marker interface for objects that are trashed"""


class IObjectTrashedEvent(IObjectEvent):
    """Event that is fired when an object is trashed"""


class IVisibleToIntranetUsersWorkspace(Interface):
    """Marker interface for workspaces
    that should be visible by all the intranet users
    """
