from src import db
from sqlalchemy.orm import mapped_column, Mapped, relationship
from sqlalchemy import Integer, String, Boolean, ForeignKey, JSON
from datetime import datetime, timezone
from typing import List, Dict


class TeacherTable(db.Model):
    __tablename__ = "teachers"

    id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True)
    firstname: Mapped[str] = mapped_column(String(255), nullable=False)
    lastname: Mapped[str] = mapped_column(String(255), nullable=True)
    username: Mapped[str] = mapped_column(String(175), nullable=False, unique=True)
    password: Mapped[str] = mapped_column(String(255), nullable=False)
    stream: Mapped[str] = mapped_column(String(10), nullable=False)
    grades: Mapped[List[Dict]] = mapped_column(JSON, nullable=False) # [{class: 5, section: "A"}, {class: 1, section: "B"}] 
    created_at: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc))
    last_login: Mapped[datetime] = mapped_column(default= lambda: datetime.now(timezone.utc))
    isLoggedIn: Mapped[str] = mapped_column(Boolean() ,default=False, nullable=False)

    school_id: Mapped[int] = mapped_column(ForeignKey("schools.id"), nullable=False)
    school = relationship("SchoolTable", back_populates="teachers")
