"""Lifecycle policies for Phase 11.10 AI content hook aggregates."""
from app.models.types import AiContentDispatchStatus as D, AiContentHookStatus as H
from app.validators.integrations import ensure_transition

_TRANSITIONS = {
    H: {
        H.DRAFT: frozenset({H.ACTIVE, H.RETIRED}),
        H.ACTIVE: frozenset({H.SUSPENDED, H.RETIRED}),
        H.SUSPENDED: frozenset({H.ACTIVE, H.RETIRED}),
        H.RETIRED: frozenset(),
    },
    D: {
        D.PENDING: frozenset({D.GENERATED, D.FAILED, D.CANCELLED}),
        D.GENERATED: frozenset(),
        D.FAILED: frozenset({D.PENDING, D.CANCELLED}),
        D.CANCELLED: frozenset(),
    },
}


class AiContentHookRegistrationPolicy:
    def assert_status_change(self, *, current, target):
        ensure_transition(current, target, _TRANSITIONS[H], "ai_content_hook_registration")


class AiContentDispatchPolicy:
    def assert_status_change(self, *, current, target):
        ensure_transition(current, target, _TRANSITIONS[D], "ai_content_dispatch")
