"""Application configuration using pydantic-settings."""
from functools import lru_cache
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """Application settings loaded from environment variables."""
    
    # Database
    database_url: str = "sqlite+aiosqlite:///./domainwatch.db"
    
    # JWT Settings
    secret_key: str = "dev-secret-key-change-in-production"
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 1440  # 24 hours
    
    # App Settings
    app_name: str = "DomainWatch"
    debug: bool = True
    
    # Email Settings (optional)
    smtp_host: str = ""
    smtp_port: int = 587
    smtp_user: str = ""
    smtp_password: str = ""
    email_from: str = ""
    
    # CORS Settings
    cors_origins: str = "http://localhost:3000,http://127.0.0.1:3000"
    
    # Scheduler Settings
    check_hour: int = 6
    check_minute: int = 0
    scheduler_check_interval_hours: int = 24
    
    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"
        extra = "ignore"  # Ignore extra fields in .env


@lru_cache()
def get_settings() -> Settings:
    """Get cached settings instance."""
    return Settings()

