# Copyright (c) CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

"""Pydantic models for CostFormation YAML structures."""

from __future__ import annotations

from pydantic import BaseModel, Field


class ForDateRangeCondition(BaseModel):
    """Date range condition for temporal cost allocation.

    Used to specify that a rule applies only during a specific time period.
    Both From and Until are required per CloudZero CFDL specification.
    """

    From: str = Field(..., description="Start date in YYYY-MM-DD format (inclusive)")
    Until: str = Field(..., description="End date in YYYY-MM-DD format (inclusive)")


class GroupRule(BaseModel):
    """A grouping rule within a dimension.

    Group rules define how source values are categorized into named groups.
    """

    Type: str = Field(default="Group", description="Rule type, always 'Group'")
    Name: str = Field(..., description="Name of the group")
    Conditions: list[dict] = Field(
        default_factory=list, description="List of conditions (Equals, Contains, ForDateRange)"
    )


class DimensionTransform(BaseModel):
    """Transform configuration for a dimension."""

    Type: str = Field(default="Normalize", description="Transform type")


class Dimension(BaseModel):
    """A dimension in the CostFormation structure.

    Dimensions define how cloud costs are categorized and organized.
    """

    Name: str = Field(..., description="Display name for the dimension")
    Source: str = Field(..., description="Source dimension to derive values from")
    Transforms: list[DimensionTransform] | None = Field(default=None, description="Optional transforms to apply")
    Rules: list[GroupRule] = Field(default_factory=list, description="List of grouping rules")


class CostFormation(BaseModel):
    """Root CostFormation structure.

    This represents the complete CostFormation YAML document structure.
    """

    Dimensions: dict[str, Dimension] = Field(
        default_factory=dict, description="Map of dimension names to configurations"
    )
