"""Attendance & Access Control schemas — Phase 9.5."""
from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, Field

from app.models.types import AccessResult, AttendanceKind, AttendanceStatus
from app.schemas.common import ORMBase


class AttendanceRecordCreate(BaseModel):
    sports_center_id: UUID
    branch_id: UUID | None = None
    member_id: UUID
    membership_id: UUID | None = None
    session_id: UUID | None = None
    attendance_kind: AttendanceKind
    status: AttendanceStatus
    recorded_at: datetime
    device_id: UUID | None = None
    gateway_id: UUID | None = None
    card_id: UUID | None = None
    pass_code: str | None = Field(default=None, max_length=100)
    notes: str | None = None
    metadata_json: dict | None = None


class AttendanceRecordRead(ORMBase):
    id: UUID
    tenant_id: UUID
    sports_center_id: UUID
    branch_id: UUID | None
    member_id: UUID
    membership_id: UUID | None
    session_id: UUID | None
    attendance_kind: AttendanceKind
    status: AttendanceStatus
    recorded_at: datetime
    device_id: UUID | None
    gateway_id: UUID | None
    card_id: UUID | None
    pass_code: str | None
    notes: str | None
    metadata_json: dict | None
    is_deleted: bool


class AccessLogRead(ORMBase):
    id: UUID
    tenant_id: UUID
    sports_center_id: UUID
    branch_id: UUID | None
    member_id: UUID | None
    membership_id: UUID | None
    device_id: UUID | None
    gateway_id: UUID | None
    access_result: AccessResult
    access_method: str | None
    credential_ref: str | None
    recorded_at: datetime
    denial_reason: str | None
    metadata_json: dict | None
    is_deleted: bool


class CheckInRequest(BaseModel):
    sports_center_id: UUID
    member_id: UUID
    membership_id: UUID | None = None
    session_id: UUID | None = None
    card_id: UUID | None = None
    pass_code: str | None = Field(default=None, max_length=100)
    device_id: UUID | None = None
    gateway_id: UUID | None = None
    notes: str | None = None


class CheckOutRequest(BaseModel):
    sports_center_id: UUID
    member_id: UUID
    membership_id: UUID | None = None
    device_id: UUID | None = None
    gateway_id: UUID | None = None
    notes: str | None = None
