from pydantic_settings import BaseSettings
from typing import List
import os


class Settings(BaseSettings):
    # Database
    DATABASE_URL: str = "postgresql://streama:streama@postgres:5432/streama2026"
    
    # Redis
    REDIS_URL: str = "redis://:redis@redis:6379/0"
    
    # JWT
    JWT_SECRET_KEY: str  # Must be set in .env - no default for security
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = 7
    
    # CORS
    ALLOWED_ORIGINS: str = "http://localhost:3000,http://localhost:8080,http://localhost:80,http://localhost"
    
    # Domain (for HTTPS URLs)
    DOMAIN: str = ""
    
    # Logging
    LOG_LEVEL: str = "INFO"
    
    # Storage
    STORAGE_PATH: str = "/app/storage"
    FFMPEG_CACHE_PATH: str = "/app/ffmpeg_cache"
    UPLOAD_PATH: str = "/app/uploads"

    # Thumbnails
    THUMBNAIL_SAMPLING_RATE: int = 1  # Extract thumbnail from every Nth segment (1 = every segment)

    # Environment
    ENVIRONMENT: str = "development"
    
    @property
    def allowed_origins_list(self) -> List[str]:
        return [origin.strip() for origin in self.ALLOWED_ORIGINS.split(",")]
    
    class Config:
        env_file = ".env"
        env_file_encoding = 'utf-8'
        case_sensitive = True
        extra = "ignore"


settings = Settings()
