"""POS Lite DTOs — Phase 12.4."""
from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, Field

from app.models.types import LifecycleStatus, PosShiftStatus, PosTicketStatus
from app.schemas.common import ORMBase


class PosRegisterCreate(BaseModel):
    venue_id: UUID
    code: str = Field(max_length=50)
    name: str = Field(max_length=255)
    status: LifecycleStatus = LifecycleStatus.ACTIVE
    description: str | None = None


class PosRegisterRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID
    code: str
    name: str
    status: LifecycleStatus
    description: str | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class PosShiftCreate(BaseModel):
    venue_id: UUID
    register_id: UUID
    opened_by: str | None = Field(default=None, max_length=100)


class PosShiftRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID
    register_id: UUID
    opened_by: str | None
    status: PosShiftStatus
    opened_at: datetime
    closed_at: datetime | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class PosTicketCreate(BaseModel):
    venue_id: UUID
    register_id: UUID
    shift_id: UUID | None = None
    table_id: UUID | None = None
    ordering_session_id: UUID | None = None
    code: str = Field(max_length=50)
    currency_code: str = Field(default="IRR", max_length=3)
    notes: str | None = None
    metadata_json: dict | None = None


class PosTicketRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID
    register_id: UUID
    shift_id: UUID | None
    table_id: UUID | None
    ordering_session_id: UUID | None
    code: str
    status: PosTicketStatus
    currency_code: str
    notes: str | None
    metadata_json: dict | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class PosTicketLineCreate(BaseModel):
    venue_id: UUID
    ticket_id: UUID
    menu_item_id: UUID
    quantity: int = 1
    modifier_option_ids: list[UUID] | None = None
    line_notes: str | None = None
    sort_order: int | None = None


class PosTicketLineRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID
    ticket_id: UUID
    menu_item_id: UUID
    quantity: int
    unit_price: int
    currency_code: str
    modifier_option_ids: list | None
    line_notes: str | None
    sort_order: int
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime
