from pydantic_settings import BaseSettings
from pathlib import Path


class Settings(BaseSettings):
    """Application settings loaded from environment variables or .env file."""

    # App
    app_name: str = "Indie Status Page"
    database_url: str = "sqlite+aiosqlite:///./data/statuspage.db"
    secret_key: str = "change-me-to-a-random-string"
    admin_api_key: str = "change-me-to-a-secure-api-key"
    debug: bool = False

    # Site
    site_name: str = "My SaaS Status"
    site_url: str = "http://localhost:8000"
    site_logo_url: str = ""
    site_accent_color: str = "#4f46e5"

    # SMTP
    smtp_host: str = ""
    smtp_port: int = 587
    smtp_user: str = ""
    smtp_pass: str = ""
    smtp_from: str = "noreply@example.com"

    # Webhook
    webhook_notify_url: str = ""

    # Uptime monitoring
    monitor_check_interval: int = 60

    model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}

    @property
    def db_path(self) -> Path:
        """Extract filesystem path from SQLite URL for directory creation."""
        # Remove the sqlite+aiosqlite:/// prefix
        path_str = self.database_url.replace("sqlite+aiosqlite:///", "")
        return Path(path_str)


settings = Settings()