from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func

from app.domain.models.base import BaseModel


class Appointment(BaseModel):
    __tablename__ = 'appointments'

    results = Column(String)
    days_until_the_next_appointment = Column(Integer)
    appointment_datetime = Column(DateTime, nullable=False, server_default=func.now())

    patient_id = Column(Integer, ForeignKey('patients.id'), nullable=False)
    doctor_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    type_id = Column(Integer, ForeignKey('appointment_types.id'), nullable=False)

    patient = relationship('Patient', back_populates='appointments')
    doctor = relationship('User', back_populates='appointments')
    type = relationship('AppointmentType', back_populates='appointments')

    files = relationship('AppointmentFile', back_populates='appointment')
