"""Foundation policies — declarative rules shells (no workflows yet)."""
from __future__ import annotations

from dataclasses import dataclass
from typing import Any


@dataclass(frozen=True)
class MembershipPolicy:
    """Membership policy document shell."""

    max_active_memberships: int | None = None
    allow_overlapping: bool = False
    require_branch: bool = False
    extras: dict[str, Any] | None = None


@dataclass(frozen=True)
class AttendancePolicy:
    """Attendance policy document shell."""

    require_active_membership: bool = True
    allow_guest: bool = False
    extras: dict[str, Any] | None = None


@dataclass(frozen=True)
class BookingPolicy:
    """Booking policy document shell."""

    allow_waiting_list: bool = True
    max_advance_days: int | None = None
    extras: dict[str, Any] | None = None


def policy_from_mapping(kind: str, data: dict[str, Any] | None):
    data = data or {}
    if kind == "membership":
        return MembershipPolicy(
            max_active_memberships=data.get("max_active_memberships"),
            allow_overlapping=bool(data.get("allow_overlapping", False)),
            require_branch=bool(data.get("require_branch", False)),
            extras=data,
        )
    if kind == "attendance":
        return AttendancePolicy(
            require_active_membership=bool(data.get("require_active_membership", True)),
            allow_guest=bool(data.get("allow_guest", False)),
            extras=data,
        )
    if kind == "booking":
        return BookingPolicy(
            allow_waiting_list=bool(data.get("allow_waiting_list", True)),
            max_advance_days=data.get("max_advance_days"),
            extras=data,
        )
    return data
