Commit 7af630f2 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Add models

parent 9c19051e
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+42 −0
Original line number Diff line number Diff line
from dataclasses import dataclass
from datetime import datetime
from uuid import UUID


@dataclass
class PartnerOP:
    id: UUID
    mcc_mnc: str
    status: str  # pending | active | suspended | decommissioned

    def is_active(self) -> bool:
        return self.status == "active"


@dataclass
class Agreement:
    id: UUID
    partner_op_id: UUID
    permitted_api_types: set[str]
    permitted_zone_ids: set[UUID]
    # partner appId -> local service_specification_id (ADR-0018)
    service_spec_mappings: dict[str, UUID]
    valid_from: datetime
    valid_until: datetime | None
    status: str  # draft | active | suspended | expired

    def is_valid_at(self, now: datetime) -> bool:
        # Expiry is checked against the clock, independent of status (RD §N step 6):
        # an agreement can still be status=active yet past valid_until.
        if now < self.valid_from:
            return False
        return self.valid_until is None or now < self.valid_until

    def permits_api(self, api_type: str) -> bool:
        return api_type in self.permitted_api_types

    def permits_zone(self, zone_id: UUID) -> bool:
        return zone_id in self.permitted_zone_ids

    def resolve_spec_id(self, app_id: str) -> UUID | None:
        return self.service_spec_mappings.get(app_id)