"""Prescription model representing medical prescriptions."""
from datetime import datetime
from typing import Annotated, Optional
from pydantic import Field, StringConstraints
from .base import BaseDocument
from .types import PyObjectId

class Prescription(BaseDocument):
    """Prescription model representing medical prescriptions."""
    # Prescription details
    prescriptionId: Annotated[
        str,
        StringConstraints(strip_whitespace=True, min_length=1)
    ] = Field(description="Unique identifier for the prescription")

    medicationId: PyObjectId = Field(description="Reference to the medication in the medications collection")
    dosage: str = Field(description="Dosage instructions for the medication")
    frequency: str = Field(description="Frequency of medication intake")
    startDate: datetime = Field(description="Start date of the prescription")
    endDate: datetime = Field(description="End date of the prescription")

    # References
    patientId: PyObjectId = Field(description="ID of the patient for whom the prescription is made")
    diagnosisId: Optional[PyObjectId] = Field(
        default=None, description="ID of the diagnosis this prescription is related to"
    )
