from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    DATABASE_URL: str = "postgresql://postgres:postgres@localhost:5432/student_archive"
    SECRET_KEY: str = "change-me-in-production-use-a-long-random-string"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7
    ALGORITHM: str = "HS256"
    UPLOAD_DIR: str = "uploads"
    BACKUP_DIR: str = "/root/grade-archive-backups"
    BACKUP_RETENTION_DAYS: int = 30
    AUTO_BACKUP_INTERVAL_HOURS: int = 24
    MAX_UPLOAD_SIZE: int = 10 * 1024 * 1024
    OLLAMA_BASE_URL: str = "http://127.0.0.1:11434"
    OLLAMA_MODEL: str = "qwen2.5:7b"
    OPENAI_BASE_URL: str = "https://api.openai.com/v1"
    OPENAI_MODEL: str = "gpt-4o-mini"
    FLUCTUATION_THRESHOLD: float = 0.08
    CORS_ORIGINS: str = "http://localhost:5173,http://localhost:23566,http://localhost"
    WEB_PORT: int = 23566
    FRONTEND_DIST: str = "../frontend/dist"
    ADMIN_DEFAULT_USERNAME: str = "admin"
    ADMIN_DEFAULT_PASSWORD: str = "admin123"
    OCR_TIMEOUT_SECONDS: int = 180
    AI_TIMEOUT_SECONDS: int = 600
    PROCESS_STALE_MINUTES: int = 20
    OCR_MAX_SIDE: int = 1280
    UPLOAD_MAX_SIDE: int = 2048
    OCR_WARMUP: bool = True
    OCR_SERVICE_URL: str = "http://127.0.0.1:23567"
    OCR_API_KEY: str = ""
    OCR_USE_GPU: bool = False
    OCR_FILTER_HANDWRITING: bool = True
    OCR_ANSWER_ZONE_RATIO: float = 0.45

    class Config:
        env_file = ".env"


settings = Settings()
