from pydantic_settings import BaseSettings
from pathlib import Path


class Settings(BaseSettings):
    APP_NAME: str = "Viral Social"
    APP_HOST: str = "0.0.0.0"
    APP_PORT: int = 8000
    DEBUG: bool = True

    DATABASE_URL: str = "sqlite:///./data/viral_social.db"

    YOUTUBE_API_KEY: str = ""

    # Cookies for TikTok/Instagram (optional - path to cookies.txt)
    TIKTOK_COOKIE_FILE: str = ""
    INSTAGRAM_COOKIE_FILE: str = ""
    # Or use browser cookies automatically: chrome, firefox, safari, edge
    COOKIES_FROM_BROWSER: str = ""

    # Paid API keys (optional - enhances discovery)
    SCRAPECREATORS_API_KEY: str = ""  # https://scrapecreators.com
    APIFY_API_TOKEN: str = ""  # https://apify.com

    DOWNLOAD_DIR: str = "./downloads"
    MAX_DOWNLOAD_QUALITY: int = 1080

    SCRAPE_INTERVAL_HOURS: int = 6
    MAX_RESULTS_PER_SCRAPE: int = 50

    # Discovery settings
    DISCOVERY_REGION: str = "BR"
    DISCOVERY_MAX_PER_PLATFORM: int = 50

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

    model_config = {"env_file": ".env", "extra": "ignore"}

    @property
    def download_path(self) -> Path:
        path = self.BASE_DIR / self.DOWNLOAD_DIR
        path.mkdir(parents=True, exist_ok=True)
        return path

    @property
    def data_path(self) -> Path:
        path = self.BASE_DIR / "data"
        path.mkdir(parents=True, exist_ok=True)
        return path


settings = Settings()
