import uuid
from sqlalchemy import Column, String, SmallInteger, Date, TIMESTAMP, ForeignKey, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
from app.db.engine import Base


class Patient(Base):
    __tablename__ = "patient"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    daily_id = Column(String(50), nullable=False)
    name = Column(String(100), nullable=False)
    age = Column(SmallInteger, nullable=False)
    gender = Column(String(20), nullable=False)
    intake_date = Column(Date, nullable=False, server_default=func.current_date())
    created_at = Column(TIMESTAMP(timezone=True), server_default=func.now(), nullable=False)
    expires_at = Column(TIMESTAMP(timezone=True), nullable=False)

    __table_args__ = (
        UniqueConstraint("daily_id", "intake_date", name="uq_patient_daily_date"),
    )
