"""Base provider models and utilities.

This module defines base classes and capabilities that all providers
can use to describe their features and constraints.
"""

from enum import Enum
from typing import List, Optional

from pydantic import BaseModel, Field


class PricingModel(str, Enum):
    """Provider pricing models."""

    MARKET = "market"  # Dynamic market-based pricing
    FIXED = "fixed"  # Fixed pricing
    HYBRID = "hybrid"  # Combination of market and fixed


class ProviderCapabilities(BaseModel):
    """Capabilities and features supported by a provider.

    This model allows the core Flow SDK to understand what features
    each provider supports without hardcoding provider-specific logic.
    """

    # Compute capabilities
    supports_spot_instances: bool = Field(
        default=False, description="Whether provider supports spot/preemptible instances"
    )
    supports_on_demand: bool = Field(
        default=True, description="Whether provider supports on-demand instances"
    )
    supports_multi_node: bool = Field(
        default=False, description="Whether provider supports multi-node tasks"
    )

    # Storage capabilities
    supports_attached_storage: bool = Field(
        default=True, description="Whether provider supports attached block storage"
    )
    supports_shared_storage: bool = Field(
        default=False, description="Whether provider supports shared filesystem storage"
    )
    storage_types: List[str] = Field(
        default_factory=lambda: ["volume"],
        description="Supported storage types (volume, nfs, object, etc.)",
    )

    # Access and security
    requires_ssh_keys: bool = Field(
        default=True, description="Whether SSH keys are required for instance access"
    )
    supports_console_access: bool = Field(
        default=False, description="Whether provider supports web console access"
    )

    # Pricing and allocation
    pricing_model: PricingModel = Field(
        default=PricingModel.FIXED, description="How instances are priced"
    )
    supports_reservations: bool = Field(
        default=False, description="Whether provider supports advance reservations"
    )

    # Regional capabilities
    supported_regions: List[str] = Field(
        default_factory=list, description="List of supported regions"
    )
    cross_region_networking: bool = Field(
        default=False, description="Whether provider supports cross-region networking"
    )

    # Resource limits
    max_instances_per_task: Optional[int] = Field(
        default=None, description="Maximum instances allowed per task"
    )
    max_storage_per_instance_gb: Optional[int] = Field(
        default=None, description="Maximum storage per instance in GB"
    )

    # Advanced features
    supports_custom_images: bool = Field(
        default=True, description="Whether custom Docker images are supported"
    )
    supports_gpu_passthrough: bool = Field(
        default=True, description="Whether GPU passthrough is supported"
    )
    supports_live_migration: bool = Field(
        default=False, description="Whether live migration is supported"
    )


class ProviderInfo(BaseModel):
    """Information about a provider."""

    name: str = Field(..., description="Provider name")
    display_name: str = Field(..., description="Human-friendly name")
    description: str = Field(..., description="Provider description")
    website: Optional[str] = Field(None, description="Provider website")
    documentation: Optional[str] = Field(None, description="Documentation URL")
    capabilities: ProviderCapabilities = Field(
        default_factory=ProviderCapabilities, description="Provider capabilities"
    )
