from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship

from app.domain.models.base import BaseModel
from app.settings import settings


class Recipient(BaseModel):
    __tablename__ = 'recipients'
    __table_args__ = {"schema": settings.SCHEMA}

    patient_id = Column(Integer, ForeignKey(f'{settings.SCHEMA}.patients.id'), nullable=False)
    mailing_id = Column(Integer, ForeignKey(f'{settings.SCHEMA}.mailing.id'), nullable=False)

    patient = relationship('Patient', back_populates='mailing')
    mailing = relationship('Mailing', back_populates='recipients')
