from typing import Optional

from pydantic import BaseModel, ConfigDict, model_validator

from core.config import get_db
from models import User


class StaffBaseSchema(BaseModel):
    first_name: str
    last_name: str
    email: str
    mobile_number: str
    dbs_status: str
    user_type: Optional[str]='staff'


class StaffCreateSchema(StaffBaseSchema):
    password: str

    @model_validator(mode="after")
    def validate(self):
        with get_db() as db:
            if db.query(User).filter(User.email == self.email).count() > 0:
                raise ValueError("User Email ID not available.Please try with another one.")
        return self


class StaffResponse(StaffBaseSchema):
    id: int
    model_config = ConfigDict(from_attributes=True)


class StaffUpdateSchema(StaffBaseSchema):
    id: int
