from simorgh.apps.modules.registry import (
    CapabilitySpec,
    FeatureFlagSpec,
    FeatureSpec,
    ModuleManifest,
    register_module,
)

register_module(
    ModuleManifest(
        name="workbox",
        version=2,
        label_key="workbox.module_label",
        domain="platform",
        description="WorkItem — canonical platform-level actionable items consumed by Workbox, Assignment, Approval, Task, Workflow, Helpdesk, CRM, HR, and DMS engines",
        capabilities=(
            CapabilitySpec(slug="work", label_key="workbox.capabilities.work",
                          description="My Work and actionable items", icon="inbox"),
        ),
        features=(
            FeatureSpec(
                code="work.workitem_my_work",
                label_key="workbox.features.my_work",
                scope="tenant",
                default_enabled=True,
                description="My Work view showing all items needing action",
            ),
            FeatureSpec(
                code="work.workitem_pending_approvals",
                label_key="workbox.features.pending_approvals",
                scope="tenant",
                default_enabled=True,
                description="Pending Approvals view for approval requests",
            ),
            FeatureSpec(
                code="work.workitem_delegated",
                label_key="workbox.features.delegated",
                scope="tenant",
                default_enabled=True,
                description="Delegated items view",
            ),
            FeatureSpec(
                code="work.workitem_overdue",
                label_key="workbox.features.overdue",
                scope="tenant",
                default_enabled=True,
                description="Overdue items view for past-due items",
            ),
            FeatureSpec(
                code="work.workitem_completed",
                label_key="workbox.features.completed",
                scope="tenant",
                default_enabled=True,
                description="Completed items view",
            ),
            FeatureSpec(
                code="work.workitem_dashboard",
                label_key="workbox.features.dashboard",
                scope="tenant",
                default_enabled=True,
                description="Workbox dashboard with count widgets and SLA risk indicators",
            ),
            FeatureSpec(
                code="work.workitem_unified_search",
                label_key="workbox.features.unified_search",
                scope="tenant",
                default_enabled=True,
                description="Unified search across all work items",
            ),
            FeatureSpec(
                code="work.workitem_realtime",
                label_key="workbox.features.realtime",
                scope="tenant",
                default_enabled=True,
                description="Real-time WebSocket updates and live counters",
            ),
            FeatureSpec(
                code="work.workitem_create",
                label_key="workbox.features.create",
                scope="tenant",
                default_enabled=True,
                description="Create canonical WorkItems from any engine",
            ),
            FeatureSpec(
                code="work.workitem_timeline",
                label_key="workbox.features.timeline",
                scope="tenant",
                default_enabled=True,
                description="WorkItem timeline tracking all state changes",
            ),
        ),
        feature_flags=(
            FeatureFlagSpec(
                name="allow_custom_workitem_filters",
                label_key="workbox.ff.allow_custom_workitem_filters",
                default=True,
                scope="tenant",
            ),
        ),
        permissions=(
            "workbox.workitem.view",
            "workbox.workitem.create",
            "workbox.workitem.complete",
            "workbox.workitem.cancel",
            "workbox.workitem.reassign",
            "workbox.item.view",
            "workbox.item.refresh",
            "workbox.dashboard.view",
            "workbox.search.use",
        ),
        events=(
            "workbox.workitem_created",
            "workbox.workitem_completed",
            "workbox.workitem_reassigned",
            "workbox.workitem_cancelled",
            "workbox.workitem_expired",

            "workbox.item_created",
            "workbox.item_updated",
            "workbox.item_removed",
            "workbox.refreshed",
        ),
    )
)
