from simorgh.apps.modules.registry import (
    CapabilitySpec,
    FeatureFlagSpec,
    FeatureSpec,
    ModuleManifest,
    register_module,
)

register_module(
    ModuleManifest(
        name="helpdesk",
        version=1,
        domain="business",
        label_key="helpdesk.module_label",
        description="Help Desk — ticket management with queues, SLA, agent teams",
        permissions=(
            "helpdesk.ticket.view",
            "helpdesk.ticket.add",
            "helpdesk.ticket.change",
            "helpdesk.ticket.delete",
            "helpdesk.ticket.assign",
            "helpdesk.ticket.close",
            "helpdesk.ticket.reopen",
            "helpdesk.ticket.merge",
            "helpdesk.reply.view",
            "helpdesk.reply.add",
            "helpdesk.reply.change",
            "helpdesk.reply.delete",
            "helpdesk.reply.note",
            "helpdesk.queue.view",
            "helpdesk.queue.add",
            "helpdesk.queue.change",
            "helpdesk.queue.delete",
            "helpdesk.category.view",
            "helpdesk.category.add",
            "helpdesk.category.change",
            "helpdesk.category.delete",
            "helpdesk.tag.view",
            "helpdesk.tag.add",
            "helpdesk.tag.change",
            "helpdesk.tag.delete",
            "helpdesk.sla.view",
            "helpdesk.sla.add",
            "helpdesk.sla.change",
            "helpdesk.sla.delete",
            "helpdesk.automation.view",
            "helpdesk.automation.add",
            "helpdesk.automation.change",
            "helpdesk.automation.delete",
            "helpdesk.team.view",
            "helpdesk.team.add",
            "helpdesk.team.change",
            "helpdesk.team.delete",
        ),
        events=(
            "helpdesk.ticket.created",
            "helpdesk.ticket.updated",
            "helpdesk.ticket.status_changed",
            "helpdesk.ticket.assigned",
            "helpdesk.ticket.escalated",
            "helpdesk.ticket.solved",
            "helpdesk.ticket.closed",
            "helpdesk.ticket.reopened",
            "helpdesk.reply.added",
            "helpdesk.sla.breached",
            "helpdesk.automation.fired",
        ),
        capabilities=(
            CapabilitySpec(slug="tickets", label_key="helpdesk.capabilities.tickets",
                          description="Ticket management and routing", icon="ticket"),
            CapabilitySpec(slug="sla", label_key="helpdesk.capabilities.sla",
                          description="SLA management", icon="clock"),
            CapabilitySpec(slug="automation", label_key="helpdesk.capabilities.automation",
                          description="Automation and workflows", icon="cog"),
            CapabilitySpec(slug="portal", label_key="helpdesk.capabilities.portal",
                          description="Customer portal", icon="globe"),
        ),
        features=(
            FeatureSpec(
                code="tickets.ticket_management",
                label_key="helpdesk.features.ticket_management",
                scope="tenant",
                default_enabled=True,
                description="Create, assign, track support tickets",
            ),
            FeatureSpec(
                code="automation.ticket_automation",
                label_key="helpdesk.features.ticket_automation",
                scope="tenant",
                default_enabled=False,
                description="Automated ticket routing, responses, workflows",
            ),
            FeatureSpec(
                code="sla.sla_management",
                label_key="helpdesk.features.sla_management",
                scope="tenant",
                default_enabled=False,
                description="Service-level agreements with breach detection",
            ),
            FeatureSpec(
                code="tickets.agent_teams",
                label_key="helpdesk.features.agent_teams",
                scope="tenant",
                default_enabled=True,
                description="Organise agents into teams with roles",
            ),
            FeatureSpec(
                code="tickets.multi_queue",
                label_key="helpdesk.features.multi_queue",
                scope="tenant",
                default_enabled=True,
                description="Multiple queues and categories for ticket organisation",
            ),
            FeatureSpec(
                code="portal.customer_portal",
                label_key="helpdesk.features.customer_portal",
                scope="tenant",
                default_enabled=False,
                description="Self-service portal for customers to submit and track tickets",
            ),
            FeatureSpec(
                code="tickets.satisfaction_survey",
                label_key="helpdesk.features.satisfaction_survey",
                scope="tenant",
                default_enabled=True,
                description="CSAT ratings and feedback collection",
            ),
            FeatureSpec(
                code="tickets.ticket_merge",
                label_key="helpdesk.features.ticket_merge",
                scope="tenant",
                default_enabled=False,
                description="Merge duplicate tickets",
            ),
            FeatureSpec(
                code="tickets.advanced_reports",
                label_key="helpdesk.features.advanced_reports",
                scope="tenant",
                default_enabled=False,
                description="Ticket volume, SLA compliance, agent performance reports",
            ),
        ),
        feature_flags=(
            FeatureFlagSpec(
                name="cross_team_notes",
                label_key="helpdesk.ff.cross_team_notes",
                default=False,
                scope="tenant",
            ),
            FeatureFlagSpec(
                name="agent_reassign",
                label_key="helpdesk.ff.agent_reassign",
                default=False,
                scope="tenant",
            ),
            FeatureFlagSpec(
                name="portal_anonymous",
                label_key="helpdesk.ff.portal_anonymous",
                default=True,
                scope="tenant",
            ),
        ),
    )
)
