from simorgh.apps.modules.registry import (
    CapabilitySpec,
    FeatureFlagSpec,
    FeatureSpec,
    ModuleManifest,
    register_module,
)

register_module(
    ModuleManifest(
        name="sla_engine",
        version=1,
        label_key="sla_engine.module_label",
        domain="platform",
        description="SLA Engine — response time and resolution SLA management across all modules including helpdesk, approvals, assignments, and office automation",
        capabilities=(
            CapabilitySpec(slug="policies", label_key="sla_engine.capabilities.policies",
                          description="SLA policies and tracking", icon="clock"),
        ),
        features=(
            FeatureSpec(
                code="policies.sla_policy_management",
                label_key="sla_engine.features.policy_management",
                scope="tenant",
                default_enabled=True,
                description="Create and manage SLA policies with configurable targets and warnings",
            ),
            FeatureSpec(
                code="policies.sla_timer_tracking",
                label_key="sla_engine.features.timer_tracking",
                scope="tenant",
                default_enabled=True,
                description="Track SLA timers per entity with pause/resume support",
            ),
            FeatureSpec(
                code="policies.sla_breach_monitoring",
                label_key="sla_engine.features.breach_monitoring",
                scope="tenant",
                default_enabled=True,
                description="Monitor SLA breaches and warnings with automated detection",
            ),
            FeatureSpec(
                code="policies.sla_recovery",
                label_key="sla_engine.features.recovery",
                scope="tenant",
                default_enabled=True,
                description="Recover breached SLAs after resolution",
            ),
        ),
        feature_flags=(
            FeatureFlagSpec(
                name="allow_business_hours_sla",
                label_key="sla_engine.ff.allow_business_hours_sla",
                default=True,
                scope="tenant",
            ),
            FeatureFlagSpec(
                name="allow_custom_warning_thresholds",
                label_key="sla_engine.ff.allow_custom_warning_thresholds",
                default=True,
                scope="tenant",
            ),
        ),
        permissions=(
            "sla_engine.policy.view",
            "sla_engine.policy.create",
            "sla_engine.policy.update",
            "sla_engine.policy.delete",
            "sla_engine.timer.view",
            "sla_engine.timer.manage",
            "sla_engine.breach.view",
        ),
        events=(
            "sla.timer.started",
            "sla.timer.paused",
            "sla.timer.resumed",
            "sla.timer.stopped",
            "sla.warning",
            "sla.breached",
            "sla.recovered",
        ),
    )
)
