"""Proactive Parquet tick cache seeder configuration (Issue #270, #278).

Seeds bigblack's local tick cache from Binance Vision archives so that
kintsugi's 64-worker Parquet path (_shard_is_parquet_cached) is always active.

Issue #278: Added ``markets`` field to configure which markets to seed
(spot, um_futures, or both).
"""

from __future__ import annotations

from pydantic_settings import BaseSettings, SettingsConfigDict


class SeederConfig(BaseSettings):
    """Tick cache seeder configuration.

    Environment Variables
    ---------------------
    OPENDEVIATIONBAR_SEEDER_HISTORICAL_START : str
        Earliest date to seed (YYYY-MM-DD). Per-symbol effective_start in
        symbols.toml overrides this when it is later (default: "2018-01-01").
    OPENDEVIATIONBAR_SEEDER_MAX_CONCURRENT_DOWNLOADS : int
        Concurrent Vision ZIP downloads per symbol batch (default: 12).
        Bigblack 1Gbps Ethernet handles 12 concurrent downloads easily
        (verified 2026-03-15: 48 files/min at 12 workers). Previous default
        of 4 was overly conservative — wasted 90% of network capacity.
    OPENDEVIATIONBAR_SEEDER_VISION_TIMEOUT_S : int
        HTTP timeout for Vision ZIP downloads in seconds (default: 120).
    OPENDEVIATIONBAR_SEEDER_HEAD_TIMEOUT_S : int
        HTTP timeout for Vision availability HEAD checks (default: 10).
    OPENDEVIATIONBAR_SEEDER_STATE_FILE : str
        Path to state file written on completion (read by monit health check).
        Default: "/var/tmp/opendeviationbar-seeder-state.txt"
    OPENDEVIATIONBAR_SEEDER_MARKETS : str
        Comma-separated list of markets to seed. Valid values: "spot",
        "um_futures". Default: "spot" (backward compatible).
        Example: "spot,um_futures" to seed both.
    OPENDEVIATIONBAR_SEEDER_REST_FALLBACK_ENABLED : bool
        Enable REST API fallback when Vision returns 404 for recent days
        (default: True). Only applies to days within rest_fallback_max_age_days.
    OPENDEVIATIONBAR_SEEDER_REST_FALLBACK_MAX_AGE_DAYS : int
        Maximum age in days for REST fallback (default: 7). REST will only
        be attempted for days 1..N days old (yesterday = age 1). Covers a
        full week of potential Vision publication lag.
    OPENDEVIATIONBAR_SEEDER_REST_FIRST_T1 : bool
        When True (default), yesterday (T-1) is seeded via REST immediately
        without waiting for Vision ZIP availability. This ensures kintsugi
        can repair yesterday from local Parquet cache on its very first pass.
        Vision will overwrite REST-sourced files on subsequent runs (D-08).
    OPENDEVIATIONBAR_SEEDER_BATCH_SIZE : int
        Number of symbols to process per seeder run (default: 6). With 18
        symbols and a 5-min timer, full rotation completes in 15 minutes.
    OPENDEVIATIONBAR_SEEDER_LAST_SEEDED_STATE_FILE : str
        Path to batch rotation state file tracking which symbols to process
        next (default: "/var/tmp/opendeviationbar-seeder-last-seeded.json").
    """

    model_config = SettingsConfigDict(
        env_prefix="OPENDEVIATIONBAR_SEEDER_",
        case_sensitive=False,
    )

    historical_start: str = "2018-01-01"
    max_concurrent_downloads: int = 12
    vision_timeout_s: int = 120
    head_timeout_s: int = 10
    state_file: str = "/var/tmp/opendeviationbar-seeder-state.txt"
    markets: str = "spot"
    rest_fallback_enabled: bool = True
    rest_fallback_max_age_days: int = 7
    rest_first_t1: bool = True
    batch_size: int = 6
    last_seeded_state_file: str = "/var/tmp/opendeviationbar-seeder-last-seeded.json"
