from typing import TYPE_CHECKING

from pydantic import validator
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlmodel import Field, Relationship, SQLModel

if TYPE_CHECKING:
    from .event import Event, EventList
    from .participant import Participant, ParticipantList


class FeedbackBase(SQLModel):
    presentation: int
    content: int
    interest: int

    comments: str = Field(default="", nullable=False)
    again: bool = Field(default=True, nullable=False)

    @validator("presentation", "content", "interest")
    def between_1_and_5(cls, value: int):
        if value < 1 or value > 5:
            raise ValueError("must be between 1 and 5 inclusive")
        return value


class Feedback(FeedbackBase, table=True):
    __tablename__ = "feedback"

    participant_id: str = Field(
        sa_column=Column(
            String(),
            ForeignKey("participants.id", ondelete="CASCADE"),
            nullable=False,
            primary_key=True,
        )
    )
    participant: "Participant" = Relationship()

    event_id: int = Field(
        sa_column=Column(
            Integer(),
            ForeignKey("events.id", ondelete="CASCADE"),
            nullable=False,
            primary_key=True,
        )
    )
    event: "Event" = Relationship(back_populates="feedback")


class FeedbackCreate(FeedbackBase):
    pass


class FeedbackList(SQLModel):
    participant: "ParticipantList"

    presentation: int
    content: int
    interest: int


class FeedbackRead(FeedbackBase):
    participant: "ParticipantList"
    event: "EventList"

pydantic.validator sqlalchemy.Integer sqlmodel.Field sqlalchemy.String sqlalchemy.ForeignKey sqlmodel.Relationship
[((402, 435), 'sqlmodel.Field', 'Field', ([], {'default': '""""""', 'nullable': '(False)'}), "(default='', nullable=False)\n", (407, 435), False, 'from sqlmodel import Field, Relationship, SQLModel\n'), ((454, 489), 'sqlmodel.Field', 'Field', ([], {'default': '(True)', 'nullable': '(False)'}), '(default=True, nullable=False)\n', (459, 489), False, 'from sqlmodel import Field, Relationship, SQLModel\n'), ((496, 544), 'pydantic.validator', 'validator', (['"""presentation"""', '"""content"""', '"""interest"""'], {}), "('presentation', 'content', 'interest')\n", (505, 544), False, 'from pydantic import validator\n'), ((1036, 1050), 'sqlmodel.Relationship', 'Relationship', ([], {}), '()\n', (1048, 1050), False, 'from sqlmodel import Field, Relationship, SQLModel\n'), ((1280, 1319), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""feedback"""'}), "(back_populates='feedback')\n", (1292, 1319), False, 'from sqlmodel import Field, Relationship, SQLModel\n'), ((856, 864), 'sqlalchemy.String', 'String', ([], {}), '()\n', (862, 864), False, 'from sqlalchemy import Column, ForeignKey, Integer, String\n'), ((878, 927), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""participants.id"""'], {'ondelete': '"""CASCADE"""'}), "('participants.id', ondelete='CASCADE')\n", (888, 927), False, 'from sqlalchemy import Column, ForeignKey, Integer, String\n'), ((1117, 1126), 'sqlalchemy.Integer', 'Integer', ([], {}), '()\n', (1124, 1126), False, 'from sqlalchemy import Column, ForeignKey, Integer, String\n'), ((1140, 1183), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""events.id"""'], {'ondelete': '"""CASCADE"""'}), "('events.id', ondelete='CASCADE')\n", (1150, 1183), False, 'from sqlalchemy import Column, ForeignKey, Integer, String\n')]