import os
import pathlib
from datetime import datetime, date, time
from decimal import Decimal
from typing import Optional, List

from fastapi import APIRouter, Depends, HTTPException, status, File, UploadFile
from fastapi.encoders import jsonable_encoder
from sqlmodel import Field, SQLModel

from ..db import get_session

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

router = APIRouter()

cert_path = '/uploads/user/{user_id}/cert/'
avatar_path = '/uploads/user/{user_id}/avatar/'


class User(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    state: str  # Statue: pending, active, inactive
    id_type_id: int
    id_number: str = None
    email = str
    email_verified_at: Optional[datetime] = None
    password: str
    remember_token: str
    hospital_id: Optional[int] = None
    hospital_node_id: Optional[int] = None
    discipline_id: int
    first_name_thai: str
    last_name_thai: str
    first_name_english: str
    last_name_english: str
    nickname: str
    birth_date: date
    gender: str
    academic_degree: str
    is_thai_address: bool
    address_house_number: str
    address_moo: str
    address_soi: str
    address_road: str
    address_tambon_id: Optional[int] = None
    address_amphoe_id: Optional[int] = None
    address_province_id: Optional[int] = None
    address_other: str
    latitude: Decimal
    longitude: Decimal
    potential: str
    avatar_path: str
    document_path: str
    policy_accept: bool
    created_at: datetime
    updated_at: datetime
    created_by: int
    updated_by: Optional[int] = None


class UserPhone(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: int
    number: str
    detail: str
    receive_sms: bool
    created_at: datetime
    updated_at: datetime
    created_by: int
    updated_by: Optional[int] = None


class UserFeedback(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: int
    feedback_type_id: Optional[int] = None
    detail: str
    created_at: datetime
    updated_at: datetime
    created_by: int
    updated_by: Optional[int] = None


class UserNotification(SQLModel, table=True):
    id: Optional[int] = 