"""Base settings class for all services."""

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class BaseAppSettings(BaseSettings):
    """Base settings class for all services"""

    model_config = SettingsConfigDict(
        env_file=".env", env_file_encoding="utf-8", case_sensitive=False, extra="ignore"
    )

    # Service identification
    service_name: str = Field(default="default-service", description="Service name")
    service_version: str = Field(default="1.0.0", description="Service version")

    # Network and security
    host: str = Field(default="0.0.0.0", description="Service host")
    port: int = Field(default=8000, description="Service port")
    internal_cidrs: list[str] = Field(
        default=["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
        description="Internal network CIDRs",
    )

    # Development settings
    dev_mode: bool = Field(
        default=False,
        description="Enable development mode (disables auth)",
        validation_alias="DEV_MODE",
    )
    disable_auth: bool = Field(
        default=False,
        description="Disable authentication middleware",
        validation_alias="DISABLE_AUTH",
    )

    # Vault configuration
    vault_addr: str = Field(
        default="http://vault:8200", description="Vault server address"
    )
    vault_role_id: str | None = Field(default=None, description="Vault AppRole role ID")
    vault_secret_id: str | None = Field(
        default=None, description="Vault AppRole secret ID"
    )
    vault_token: str | None = Field(default=None, description="Vault token (dev only)")
    vault_mount_point: str = Field(
        default="transit", description="Vault transit mount point"
    )

    # Database URLs
    postgres_url: str = Field(
        default="postgresql://user:pass@postgres:5432/taxagent",
        description="PostgreSQL connection URL",
    )
    neo4j_uri: str = Field(
        default="bolt://neo4j:7687", description="Neo4j connection URI"
    )
    neo4j_user: str = Field(default="neo4j", description="Neo4j username")
    neo4j_password: str = Field(default="password", description="Neo4j password")
    redis_url: str = Field(
        default="redis://redis:6379", description="Redis connection URL"
    )

    # Object storage
    minio_endpoint: str = Field(default="minio:9000", description="MinIO endpoint")
    minio_access_key: str = Field(default="minioadmin", description="MinIO access key")
    minio_secret_key: str = Field(default="minioadmin", description="MinIO secret key")
    minio_secure: bool = Field(default=False, description="Use HTTPS for MinIO")

    # Vector database
    qdrant_url: str = Field(
        default="http://qdrant:6333", description="Qdrant server URL"
    )
    qdrant_api_key: str | None = Field(default=None, description="Qdrant API key")

    # Event bus configuration
    event_bus_type: str = Field(
        default="nats", description="Event bus type: nats, kafka, sqs, or memory"
    )

    # NATS configuration
    nats_servers: str = Field(
        default="nats://localhost:4222",
        description="NATS server URLs (comma-separated)",
    )
    nats_stream_name: str = Field(
        default="TAX_AGENT_EVENTS", description="NATS JetStream stream name"
    )
    nats_consumer_group: str = Field(
        default="tax-agent", description="NATS consumer group name"
    )

    # Kafka configuration (legacy)
    kafka_bootstrap_servers: str = Field(
        default="localhost:9092", description="Kafka bootstrap servers"
    )

    # AWS configuration
    aws_region: str = Field(default="us-east-1", description="AWS region for SQS/SNS")

    # Observability
    otel_service_name: str | None = Field(
        default=None, description="OpenTelemetry service name"
    )
    otel_exporter_endpoint: str | None = Field(
        default=None, description="OTEL exporter endpoint"
    )
    log_level: str = Field(default="INFO", description="Log level")

    # Performance
    max_workers: int = Field(default=4, description="Maximum worker threads")
    request_timeout: int = Field(default=30, description="Request timeout in seconds")
