import os
from pathlib import Path
from pydantic_settings import BaseSettings

BASE_DIR = Path(__file__).resolve().parent.parent

class Settings(BaseSettings):
    PROJECT_NAME: str = "MAP LiveMirror VTON Platform"
    COMPANY_NAME: str = "Media Artha Persada"
    VERSION: str = "1.0.0"
    API_V1_PREFIX: str = "/api/v1"
    
    # Paths
    BASE_DIR: Path = BASE_DIR
    STATIC_DIR: Path = BASE_DIR / "app" / "static"
    TEMPLATES_DIR: Path = BASE_DIR / "app" / "templates"
    UPLOAD_DIR: Path = BASE_DIR / "app" / "static" / "uploads"
    CLOTH_UPLOAD_DIR: Path = BASE_DIR / "app" / "static" / "uploads" / "clothes"
    CUTOUT_UPLOAD_DIR: Path = BASE_DIR / "app" / "static" / "uploads" / "cutouts"
    
    # Database
    DATABASE_URL: str = f"sqlite:///{BASE_DIR}/mapvton.db"
    
    # Decart AI Model Config
    DECART_DEFAULT_MODEL: str = "lucy-vton-3.5"
    DECART_API_BASE_URL: str = "https://api.decart.ai/v1"
    
    # Fleet Monitor Settings
    HEARTBEAT_TIMEOUT_SECONDS: int = 30
    
    class Config:
        case_sensitive = True

settings = Settings()

# Ensure directories exist
settings.UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
settings.CLOTH_UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
settings.CUTOUT_UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
