from typing import TYPE_CHECKING, List, Optional

from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import ARRAY
from sqlmodel import AutoString, Field, Relationship, SQLModel

if TYPE_CHECKING:
    from .application import Application, ApplicationList


class SchoolBase(SQLModel):
    name: str

    abbreviations: List[str] = Field(
        default=[],
        sa_column=Column(ARRAY(AutoString()), nullable=False),
    )
    alternatives: List[str] = Field(
        default=[],
        sa_column=Column(ARRAY(AutoString()), nullable=False),
    )


class School(SchoolBase, table=True):
    __tablename__ = "schools"

    id: Optional[str] = Field(default=None, primary_key=True, nullable=False)
    needs_review: bool = False

    applications: List["Application"] = Relationship(back_populates="school")


class SchoolCreate(SchoolBase):
    pass


class SchoolList(SQLModel):
    id: str
    name: str
    needs_review: bool


class SchoolRead(SchoolBase):
    id: str
    needs_review: bool
    applications: List["ApplicationList"]


class SchoolUpdate(SQLModel):
    name: Optional[str]

    needs_review: Optional[bool]

    abbreviations: Optional[List[str]]
    alternatives: Optional[List[str]]

sqlmodel.Relationship sqlmodel.AutoString sqlmodel.Field
[((662, 715), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)', 'nullable': '(False)'}), '(default=None, primary_key=True, nullable=False)\n', (667, 715), False, 'from sqlmodel import AutoString, Field, Relationship, SQLModel\n'), ((788, 825), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""school"""'}), "(back_populates='school')\n", (800, 825), False, 'from sqlmodel import AutoString, Field, Relationship, SQLModel\n'), ((403, 415), 'sqlmodel.AutoString', 'AutoString', ([], {}), '()\n', (413, 415), False, 'from sqlmodel import AutoString, Field, Relationship, SQLModel\n'), ((529, 541), 'sqlmodel.AutoString', 'AutoString', ([], {}), '()\n', (539, 541), False, 'from sqlmodel import AutoString, Field, Relationship, SQLModel\n')]