"""Provider Configuration Schemas"""
from typing import Optional, List, Dict, Any, Union
from pydantic import BaseModel, Field, ConfigDict


class ControlOption(BaseModel):
    """An option for a select control"""
    model_config = ConfigDict(populate_by_name=True)

    value: Union[str, int, bool, float]
    label: str
    description: Optional[str] = None


class ProviderControl(BaseModel):
    """A single control/input for a provider"""
    model_config = ConfigDict(populate_by_name=True)

    name: str
    label: str
    type: str  # select, number, slider, checkbox, text, textarea
    description: Optional[str] = None
    default: Any
    options: Optional[List[ControlOption]] = None
    min: Optional[float] = None
    max: Optional[float] = None
    step: Optional[float] = None
    required: Optional[bool] = False
    depends_on: Optional[Dict[str, Any]] = Field(default=None, alias="dependsOn")  # {control: name, value: expected_value}


class ProviderModel(BaseModel):
    """A model offered by a provider"""
    model_config = ConfigDict(populate_by_name=True)

    id: str
    name: str
    description: Optional[str] = None
    controls: Optional[List[ProviderControl]] = None  # Model-specific controls


class ProviderConfig(BaseModel):
    """Complete provider configuration"""
    model_config = ConfigDict(populate_by_name=True, alias_generator=lambda x: ''.join(word.capitalize() if i > 0 else word for i, word in enumerate(x.split('_'))))

    id: str
    name: str
    description: Optional[str] = None
    models: List[ProviderModel]
    default_model: str = Field(alias="defaultModel")
    common_controls: List[ProviderControl] = Field(alias="commonControls")
    features: List[str]
