"""Lifecycle policies for Phase 11.10 analytics aggregates."""
from app.models.types import AnalyticsReportStatus as R, AnalyticsSnapshotStatus as S
from app.validators.integrations import ensure_transition

_TRANSITIONS = {
    R: {
        R.DRAFT: frozenset({R.ACTIVE, R.ARCHIVED}),
        R.ACTIVE: frozenset({R.ARCHIVED}),
        R.ARCHIVED: frozenset(),
    },
    S: {
        S.ACTIVE: frozenset({S.ARCHIVED}),
        S.ARCHIVED: frozenset(),
    },
}


class AnalyticsReportDefinitionPolicy:
    def assert_status_change(self, *, current, target):
        ensure_transition(current, target, _TRANSITIONS[R], "analytics_report_definition")


class AnalyticsSnapshotPolicy:
    def assert_status_change(self, *, current, target):
        ensure_transition(current, target, _TRANSITIONS[S], "analytics_snapshot")
