"""Pydantic data models for the Terraform MCP server."""

from __future__ import annotations

from pydantic import BaseModel, Field


class VariableInfo(BaseModel):
    """A Terraform variable parsed from variables.tf."""

    name: str
    type: str
    description: str = ""
    default: str | None = None
    required: bool = True
    validation: str | None = None


class OutputInfo(BaseModel):
    """A Terraform output parsed from outputs.tf."""

    name: str
    description: str = ""


class CostEstimate(BaseModel):
    """Cost information parsed from the comment block at the top of main.tf."""

    raw_text: str = ""
    line_items: list[str] = Field(default_factory=list)


class ModuleInfo(BaseModel):
    """Complete parsed information for one Terraform module."""

    name: str
    cloud: str = ""
    description: str = ""
    variables: list[VariableInfo] = Field(default_factory=list)
    outputs: list[OutputInfo] = Field(default_factory=list)
    cost_estimate: CostEstimate = Field(default_factory=CostEstimate)
    readme: str = ""
    examples: str = ""
    source_path: str = ""


class WiringEntry(BaseModel):
    """Maps a source module output to a target module input."""

    source_output: str
    target_input: str


class ModuleDependency(BaseModel):
    """Dependency relationship between two modules."""

    source: str
    target: str
    wiring: list[WiringEntry] = Field(default_factory=list)


class StackModuleRequest(BaseModel):
    """A module requested for stack generation."""

    name: str
    instance_name: str | None = None
    config: dict[str, str] = Field(default_factory=dict)


class CostRequest(BaseModel):
    """A module + tier pair for cost estimation."""

    name: str
    tier: str = "dev"
