"""File holds all model definitions of SQL tables.""" from sqlalchemy.dialects.mysql import BIGINT, VARCHAR from sqlmodel import Column, Field, ForeignKey, Relationship, SQLModel class ElectionInformation(SQLModel, table=True): """Represents all required information for an election. Attributes: name: Name of the election. thread_id: Thread of where all the election related messages take place. council_vote_msg_id: Message where the council vote is presented. high_council_vote_msg_id: Message where the high council vote is presented. council_nomination_msg_id: Message where council nomination button is held. high_council_nomination_msg_id: Message where high council nomination button is held. """ name: str = Field(sa_column=Column("ElectionName", VARCHAR, primary_key=True, unique=True), max_length=30) thread_id: int = Field(sa_column=Column("ThreadId", BIGINT(unsigned=True), nullable=False)) council_vote_msg_id: int | None = Field( sa_column=Column("CouncilVoteMsgId", BIGINT(unsigned=True), nullable=True), default=None ) high_council_vote_msg_id: int | None = Field( sa_column=Column("HighCouncilVoteMsgId", BIGINT(unsigned=True), nullable=True), default=None ) council_nomination_msg_id: int | None = Field( sa_column=Column("CouncilNominationMsgId", BIGINT(unsigned=True), nullable=True), default=None ) high_council_nomination_msg_id: int | None = Field( sa_column=Column("HighCouncilNominationMsgId", BIGINT(unsigned=True), nullable=True), default=None ) council_members: list["CouncilMembers"] = Relationship(back_populates="election", cascade_delete=True) class CouncilMembers(SQLModel, table=True): """Represents members involved in a given election. Records speech message ids for general election and high council position. Booleans record if the user was elected to a council/high council position. Attributes: member_id: User that is running for council's discord id. speech_msg_id: Message id of user's speech. elected: Whether the user got elected to council. discord_manager: Whether the user got elected to the Discord Manager position. clan_leader: Whether the user got elected to the Clan Leader position. discord_manager_speech_id: Message id of the user's Discord Manager speech. clan_leader_speech_id: Message id of the user's Clan Leader speech. """ election_name: str = Field( sa_column=Column( "ElectionName", VARCHAR, ForeignKey("ElectionInformation.ElectionName", ondelete="CASCADE"), primary_key=True, ), max_length=30, ) member_id: int = Field(sa_column=Column("MemberId", BIGINT(unsigned=True), primary_key=True, nullable=False)) speech_msg_id: int = Field(sa_column=Column("SpeechMsgId", BIGINT(unsigned=True), nullable=False)) elected: bool = Field(sa_column=Column("Elected"), default=False) discord_manager: bool = Field(sa_column=Column("DiscordManager"), default=False) clan_leader: bool = Field(sa_column=Column("ClanLeader"), default=False) discord_manager_speech_id: int = Field( sa_column=Column("DiscordManagerSpeechId", BIGINT(unsigned=True), nullable=True) ) clan_leader_speech_id: int = Field(sa_column=Column("ClanLeaderSpeechId", BIGINT(unsigned=True), nullable=True)) election: ElectionInformation | None = Relationship(back_populates="council_members")