"""Operation model for medical operations."""
from datetime import UTC, datetime
from typing import Annotated, List, Optional

from pydantic import Field, StringConstraints

from .base import BaseDocument
from .types import PyObjectId

class Operation(BaseDocument):
    """Operation model representing medical operations."""
    # Operation details
    operationId: Annotated[
        str,
        StringConstraints(min_length=1, strip_whitespace=True)
    ] = Field(description="Unique identifier for the operation")
    name: Annotated[
        str,
        StringConstraints(min_length=1, strip_whitespace=True)
    ] = Field(description="Name of the operation")
    sutCode: Annotated[
        str,
        StringConstraints(min_length=1, strip_whitespace=True)
    ] = Field(description="SUT Code of the operation")

    description: Optional[str] = Field(
        default=None, description="Description of the operation"
    )
    date: Optional[datetime] = Field(
        default_factory=lambda: datetime.now(UTC),
        description="Date of the operation in YYYY-MM-DD format"
    )

    # Patient reference
    patientId: PyObjectId = Field(description="ID of the patient who was operated on")

    # Practitioner references
    practitionerIds: List[
        Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)]
    ] = Field(description="List of IDs of practitioners who performed the operation")
