"""Calendar integration OAuth and sync settings."""

from typing import Annotated

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

from noteflow.config.settings._base import ENV_FILE, EXTRA_IGNORE


class CalendarIntegrationSettings(BaseSettings):
    """Calendar integration OAuth and sync settings.

    Note: This is distinct from CalendarTriggerSettings in triggers/calendar.py,
    which handles trigger detection heuristics.

    Environment variables use NOTEFLOW_CALENDAR_ prefix:
        NOTEFLOW_CALENDAR_GOOGLE_CLIENT_ID: Google OAuth client ID
        NOTEFLOW_CALENDAR_GOOGLE_CLIENT_SECRET: Google OAuth client secret
        NOTEFLOW_CALENDAR_OUTLOOK_CLIENT_ID: Microsoft OAuth client ID
        NOTEFLOW_CALENDAR_OUTLOOK_CLIENT_SECRET: Microsoft OAuth client secret
        NOTEFLOW_CALENDAR_REDIRECT_URI: OAuth callback URI
        NOTEFLOW_CALENDAR_SYNC_HOURS_AHEAD: Hours to look ahead for events
        NOTEFLOW_CALENDAR_MAX_EVENTS: Maximum events to fetch
        NOTEFLOW_CALENDAR_SYNC_INTERVAL_MINUTES: Sync interval in minutes
    """

    model_config = SettingsConfigDict(
        env_prefix="NOTEFLOW_CALENDAR_",
        env_file=ENV_FILE,
        env_file_encoding="utf-8",
        extra=EXTRA_IGNORE,
    )

    # Google OAuth
    google_client_id: Annotated[
        str,
        Field(default="", description="Google OAuth client ID"),
    ]
    google_client_secret: Annotated[
        str,
        Field(default="", description="Google OAuth client secret"),
    ]

    # Microsoft OAuth
    outlook_client_id: Annotated[
        str,
        Field(default="", description="Microsoft OAuth client ID"),
    ]
    outlook_client_secret: Annotated[
        str,
        Field(default="", description="Microsoft OAuth client secret"),
    ]

    # OAuth redirect
    redirect_uri: Annotated[
        str,
        Field(default="noteflow://oauth/callback", description="OAuth callback URI"),
    ]

    # Sync settings
    sync_hours_ahead: Annotated[
        int,
        Field(default=24, ge=1, le=168, description="Hours to look ahead for events"),
    ]
    max_events: Annotated[
        int,
        Field(default=20, ge=1, le=100, description="Maximum events to fetch"),
    ]
    sync_interval_minutes: Annotated[
        int,
        Field(default=15, ge=1, le=1440, description="Sync interval in minutes"),
    ]
