from functools import lru_cache
from typing import List, Optional
from pydantic_settings import BaseSettings, SettingsConfigDict

class SuperAdminItem(BaseSettings):
    email: str
    password: str
    first_name: Optional[str] = "System"
    last_name: Optional[str] = "Administrator"

class Settings(BaseSettings):
    """
    Application configuration settings loaded from environment variables.
    """

    # CORS
    BACKEND_CORS_ORIGINS: list[str] = ["*"]

    # Database
    DATABASE_URL: str = "sqlite:///./story-book.db"

    # Security
    SECRET_KEY: str
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7

    # Uploads & Limits
    MAX_PROFILE_IMG_SIZE: int = 6 * 1024 * 1024  # 6MB
    MAX_PRODUCT_IMG_SIZE: int = 100 * 1024 * 1024  # 100MB
    MAX_PRODUCT_UPLOAD_BYTES: int = 50 * 1024 * 1024  # 50MB
    CHUNK_SIZE: int = 1024 * 1024  # 1MB

    # Directories
    PROFILE_IMAGE_DIRECTORY: str = "assets/profile_image/"
    COLLAGE_IMAGES_DIRECTORY: str = "assets/collage_images/"
    PSD_FILES_DIRECTORY: str = "assets/psd_files/"
    OVERLAY_IMAGES_DIRECTORY: str ="assets/overlay_images/"
    LOGO_IMAGES_DIRECTORY: str ="assets/logo_images/"
    FINAL_IMAGES_DIRECTORY: str ="assets/final_images/"

    # Super Admin
    SUPERADMINS: List[SuperAdminItem] = []

    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")


@lru_cache()
def get_settings() -> Settings:
    """Retrieve cached application settings."""
    return Settings()
