from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pydantic import BaseModel

SQLALCHEMY_DATABASE_URL = "sqlite:///./chepuhagram.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
Base.metadata.create_all(bind=engine)

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True, index=True)
    first_name = Column(String(50), nullable=False, server_default="User")
    last_name = Column(String(50), nullable=True)
    username = Column(String, unique=True, index=True)
    about = Column(String, nullable=True)
    phone = Column(String(20), unique=True, nullable=True)
    totp_secret = Column(String(32), nullable=True)
    hashed_password = Column(String)
    public_key = Column(String, nullable=True)
    
class RefreshRequest(BaseModel):
    refresh_token: str

Base.metadata.create_all(bind=engine)