from enum import Enum
from typing import TYPE_CHECKING, Optional

from sqlalchemy import Column
from sqlalchemy import Enum as SQLEnum
from sqlalchemy import ForeignKey, Integer
from sqlmodel import Field, Relationship, SQLModel

if TYPE_CHECKING:
    from .message import Message, MessageList


class MessageTriggerType(Enum):
    SIGN_UP = "Sign Up"
    APPLICATION_SUBMITTED = "Application - Submitted"
    APPLICATION_ACCEPTED = "Application - Accepted"
    APPLICATION_REJECTED = "Application - Rejected"
    INCOMPLETE_APPLICATION_24H = "Incomplete Application - 24hr"
    INCOMPLETE_APPLICATION_7D = "Incomplete Application - 7 day"


class MessageTriggerBase(SQLModel):
    trigger: MessageTriggerType = Field(
        sa_column=Column(
            SQLEnum(MessageTriggerType),
            nullable=False,
            primary_key=True,
        )
    )


class MessageTrigger(MessageTriggerBase, table=True):
    __tablename__ = "message_triggers"

    message_id: Optional[int] = Field(
        sa_column=Column(
            Integer(),
            ForeignKey("messages.id", ondelete="CASCADE"),
            nullable=True,
        )
    )

    message: Optional["Message"] = Relationship()


class MessageTriggerRead(MessageTriggerBase):
    message: Optional["MessageList"]


class MessageTriggerUpdate(SQLModel):
    message_id: Optional[int]

sqlalchemy.Integer sqlalchemy.Enum sqlalchemy.ForeignKey sqlmodel.Relationship
[((1182, 1196), 'sqlmodel.Relationship', 'Relationship', ([], {}), '()\n', (1194, 1196), False, 'from sqlmodel import Field, Relationship, SQLModel\n'), ((757, 784), 'sqlalchemy.Enum', 'SQLEnum', (['MessageTriggerType'], {}), '(MessageTriggerType)\n', (764, 784), True, 'from sqlalchemy import Enum as SQLEnum\n'), ((1033, 1042), 'sqlalchemy.Integer', 'Integer', ([], {}), '()\n', (1040, 1042), False, 'from sqlalchemy import ForeignKey, Integer\n'), ((1056, 1101), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""messages.id"""'], {'ondelete': '"""CASCADE"""'}), "('messages.id', ondelete='CASCADE')\n", (1066, 1101), False, 'from sqlalchemy import ForeignKey, Integer\n')]