from datetime import datetime
from uuid import UUID
from pydantic import ConfigDict
from fastapi import Form

from backend.core.security.security import hash_password
from backend.schemas.main_model import MainModel

class UserBase(MainModel):
  username: str = Form(...)

class UserRequest(UserBase):
  password: str = Form(...)

class UserCreate(UserRequest):
  name: str

class UserProfile(MainModel):
  name: str | None = None
  password: str | None = None
  is_admin: bool | None = None
  is_lock: bool | None = None
  model_config = ConfigDict(from_attributes=True)

  def update_password(self):
    self.password = (None if self.password is None else hash_password(self.password))

class UserSeeds(UserCreate):
  is_admin: bool
  is_lock: bool

class PrivateUser(UserBase):
  id: UUID
  name: str
  is_admin: bool
  is_lock: bool
  created_at: datetime
  updated_at: datetime
  model_config = ConfigDict(from_attributes=True)

class ProfileResponse(UserBase):
  name: str
  is_admin: bool
  created_at: datetime
  updated_at: datetime
  model_config = ConfigDict(from_attributes=True)

class LoginResponse(MainModel):
  access_token: str
  exp: int
  name: str
