# generated by datamodel-codegen:
#   filename:  DehydrationMetadataV1.schema.json
#   timestamp: 2025-06-27T20:31:23+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import List, Optional, Union

from pydantic import BaseModel, Field, confloat, conint


class FeederCategory(Enum):
    """
    An enumeration of feeder categories representing it's area type.
    """

    Urban = "Urban"
    Suburban = "Suburban"
    Rural = "Rural"


class Metadata(BaseModel):
    """
    Contains information about location, creation date and model year.
    """

    state: Union[str, List[str]] = Field(
        ...,
        description="U.S State to which model belongs to.",
        title="List U.S state to which model belongs to.",
    )
    created_at: datetime = Field(
        ..., description="Data obfuscation date-time.", title="Created Datetime"
    )
    model_year: int = Field(
        ..., description="Model year from which data is extracted.", title="Model Year"
    )
    info: str = Field(
        ..., description="Any description you would like to add.", title="Metadata Info"
    )
    region_type: FeederCategory = Field(
        ...,
        description="An enumeration of feeder categories representing it's area type.",
        title="Feeder Category",
    )


class TransformerItem(BaseModel):
    """
    Object capturing high level information about transformer item.
    """

    kva: conint(ge=1) = Field(
        ..., description="Transformer capacity on kVA.", title="Capacity in kVA"
    )
    count: conint(ge=1) = Field(
        ..., description="Number of transformers.", title="Transformer Count"
    )
    is_regulator: bool = Field(..., description="True if regulator.", title="Is Regulator")
    is_substation_transformer: bool = Field(
        ...,
        description="Set to true if these are substation transformers.",
        title="Is Substation Transformer",
    )
    num_phase: conint(ge=1, le=3) = Field(
        ..., description="Transformer number of phase.", title="Number of Phase"
    )
    high_kv: confloat(ge=0.01) = Field(
        ...,
        description="Kilovolt rating for high voltage side.",
        title="High Voltage kV",
    )
    low_kv: confloat(ge=0.01) = Field(
        ..., description="Kilovolt rating for low voltage side.", title="Low Voltage kV"
    )
    avg_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Average number of customer served downward from these type of transformers.",
        title="Average Customers Served",
    )
    min_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Minimum number of customer served downward from these type of transformers.",
        title="Minimum Customers Served",
    )
    max_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Maximum number of customer served downward from these type of transformers.",
        title="Maximum Customers Served",
    )
    std_customers_served: Union[float, str] = Field(
        ...,
        description="Standard deviation number of customer served downward from these type of transformers.",
        title="Standard Deviation Customers Served",
    )
    min_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Minimum percentage loading of these type of transformers during peak load.",
        title="Minimum Percentage Peak Loading",
    )
    avg_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Average percentage loading of these type of transformers during peak load.",
        title="Average Percentage Peak Loading",
    )
    max_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Maximum percentage loading of these type of transformers during peak load.",
        title="Maximum Percentage Peak Loading",
    )
    std_pct_peak_loading: Union[float, str] = Field(
        ...,
        description="Standard deviation percentage loading of these type of transformers during peak load.",
        title="Standard Deviation Percentage Peak Loading",
    )


class FeederSectionItem(BaseModel):
    """
    Object representing high level information about feeder section item.
    """

    kv: confloat(ge=0.01) = Field(
        ...,
        description="Kilo volt rating of feeder section. Line to line for multi phase and line to ground for single phase.",
        title="Feeder Section Voltage",
    )
    num_phase: confloat(ge=1.0, le=3.0) = Field(
        ...,
        description="Number of phase for feeder section.",
        title="Feeder section number of phase.",
    )
    count: confloat(ge=1.0) = Field(
        ...,
        description="Number of feeder section for given voltage rating, num of phase and construction type.",
        title="Feeder Section Count",
    )
    avg_feeder_miles: confloat(ge=0.0) = Field(
        ...,
        description="Average feeder section length in miles.",
        title="Average Feeder Miles",
    )
    min_feeder_miles: confloat(ge=0.0) = Field(
        ...,
        description="Minimum feeder section length in miles.",
        title="Minimum Feeder Miles",
    )
    max_feeder_miles: confloat(ge=0.0) = Field(
        ...,
        description="Maximum feeder section length in miles.",
        title="Maximum Feeder Miles",
    )
    std_feeder_miles: Union[float, str] = Field(
        ...,
        description="Standard deviation feeder section length in miles.",
        title="Standard Deviation Feeder Miles",
    )
    min_ampacity: confloat(ge=0.0) = Field(
        ...,
        description=" feeder section ampere capacity.",
        title="Minimum Feeder Ampacity",
    )
    avg_ampacity: confloat(ge=0.0) = Field(
        ...,
        description="Average feeder section ampere capacity.",
        title="Average Feeder Ampacity",
    )
    max_ampacity: confloat(ge=0.0) = Field(
        ...,
        description="Maximum feeder section ampere capacity.",
        title="Maximum Feeder Ampacity",
    )
    std_ampacity: Union[float, str] = Field(
        ...,
        description="Standard deviation feeder section ampere capacity.",
        title="Standard Deviation Feeder Ampacity",
    )
    avg_per_unit_resistance_ohm_per_mile: float = Field(
        ...,
        description="Average per unit resistance for feeder sections.",
        title="Average Per Unit Resistance",
    )
    min_per_unit_resistance_ohm_per_mile: float = Field(
        ...,
        description="Minimum per unit resistance for feeder sections.",
        title="Minimum Per Unit Resistance",
    )
    max_per_unit_resistance_ohm_per_mile: float = Field(
        ...,
        description="Maximum per unit resistance for feeder sections.",
        title="Maximum Per Unit Resistance",
    )
    std_per_unit_resistance_ohm_per_mile: Union[float, str] = Field(
        ...,
        description="Standard Deviation of per unit resistance for feeder sections.",
        title="Standard Deviation Per Unit Resistance",
    )
    avg_per_unit_reactance_ohm_per_mile: float = Field(
        ...,
        description="Average per unit reactance for feeder sections.",
        title="Average Per Unit Reactance",
    )
    min_per_unit_reactance_ohm_per_mile: float = Field(
        ...,
        description="Minimum per unit reactance for feeder sections.",
        title="Minimum Per Unit Reactance",
    )
    max_per_unit_reactance_ohm_per_mile: float = Field(
        ...,
        description="Maximum per unit reactance for feeder sections.",
        title="Maximum Per Unit Reactance",
    )
    std_per_unit_reactance_ohm_per_mile: Union[float, str] = Field(
        ...,
        description="Standard Deviation of per unit reactance for feeder sections.",
        title="Standard Deviation Per Unit Reactance",
    )
    min_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Minimum number of customers served directly or downward from this feeder section.",
        title="Minimum number of customers served.",
    )
    avg_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Average number of customers served directly or downward from this feeder section.",
        title="Average number of customers served.",
    )
    max_customers_served: confloat(ge=0.0) = Field(
        ...,
        description="Maximum number of customers served directly or downward from this feeder section.",
        title="Maximum number of customers served.",
    )
    std_customers_served: Union[float, str] = Field(
        ...,
        description="Standard deviation number of customers served directly or downward from this feeder section.",
        title="Standard Deviation number of customers served.",
    )
    min_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Minimum percentage loading of these type of feeder sections during peak load.",
        title="Minimum Percentage Peak Loading",
    )
    avg_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Average percentage loading of these type of feeder sections during peak load.",
        title="Average Percentage Peak Loading",
    )
    max_pct_peak_loading: confloat(ge=0.0) = Field(
        ...,
        description="Maximum percentage loading of these type of feeder sections during peak load.",
        title="Maximum Percentage Peak Loading",
    )
    std_pct_peak_loading: Union[float, str] = Field(
        ...,
        description="Standard deviation percentage loading of these type of feeder sections during peak load.",
        title="Standard Deviation Percentage Peak Loading",
    )


class CapacitorItem(BaseModel):
    """
    Object representing high level information of a given type of capacitor.
    """

    kvar: confloat(ge=0.01) = Field(
        ...,
        description="Nameplate rating of capacitor in kvar.",
        title="Capacitor Capacity",
    )
    num_phase: confloat(ge=1.0, le=3.0) = Field(
        ...,
        description="Number of phase for capacitor",
        title="Capacitor Number of Phase",
    )
    kv: confloat(ge=0.01) = Field(
        ..., description="Kilo volt rating for the capacitor.", title="Capacitor kV"
    )
    count: confloat(ge=1.0) = Field(
        ..., description="Count of capacitors.", title="Capacitor Count"
    )


class SwitchItem(BaseModel):
    """
    Object representing high level information about given type of switch.
    """

    num_phase: confloat(le=3.0) = Field(
        ...,
        description="Number of phase for switch item.",
        title="Switch Number Of Phase",
    )
    kv: confloat(ge=0.01) = Field(
        ..., description="Switch voltage rating in kV.", title="Switch kV"
    )
    is_normally_open: bool = Field(
        ...,
        description="Set to true if this switch is normally open.",
        title="Is Normally Open",
    )
    count: confloat(ge=1.0) = Field(..., description="Count of switches.", title="Switch Count")
    avg_ampacity: confloat(ge=0.0) = Field(
        ...,
        description="Average switch rating in ampere.",
        title="Average Switch Ampacity",
    )
    min_ampacity: confloat(ge=0.0) = Field(
        ...,
        description="Minimum switch rating in ampere.",
        title="Minimum Switch Ampacity",
    )
    max_ampacity: confloat(ge=0.0) = Field(
        ...,
        description="Maximum switch rating in ampere.",
        title="Maximum Switch Ampacity",
    )
    std_ampacity: Union[float, str] = Field(
        ...,
        description="Standard deviation switch rating in ampere.",
        title="Standard Deviation Switch Ampacity",
    )


class LoadItem(BaseModel):
    """
    High level information about load item.
    """

    kv: confloat(ge=0.0) = Field(
        ..., description="Load voltage rating in kilovolt.", title="Load Voltage Rating"
    )
    count: confloat(ge=1.0) = Field(..., description="Count of loads.", title="Load Count")
    num_phase: confloat(ge=1.0, le=3.0) = Field(
        ..., description="Loads number of phase.", title="Number of Phase"
    )
    total_customer: confloat(ge=1.0) = Field(
        ..., description="Count of total customers.", title="Total Customer Count"
    )
    avg_customers_per_load: confloat(ge=1.0) = Field(
        ...,
        description="Average count of customers per load.",
        title="Average Customers Per Load",
    )
    min_customers_per_load: confloat(ge=1.0) = Field(
        ...,
        description="Minimum count of customers per load.",
        title="Minimum Customers Per Load",
    )
    max_customers_per_load: confloat(ge=1.0) = Field(
        ...,
        description="Maximum count of customers per load.",
        title="Maximum Customers Per Load",
    )
    std_customers_per_load: Union[float, str] = Field(
        ...,
        description="Standard deviation count of customers per load.",
        title="Standard Deviation Customers Per Load",
    )
    avg_peak_kw: confloat(ge=0.0) = Field(
        ...,
        description="Average peak active power consumption in kW.",
        title="Average Peak kW",
    )
    avg_peak_kvar: confloat(ge=0.0) = Field(
        ...,
        description="Average peak reactive power consumption in kVAR.",
        title="Average Peak kVAR",
    )
    min_peak_kw: confloat(ge=0.0) = Field(
        ...,
        description="Minimum peak active power consumption in kW.",
        title="Minimum Peak kW",
    )
    min_peak_kvar: confloat(ge=0.0) = Field(
        ...,
        description="Minimum peak reactive power consumption in kVAR.",
        title="Minimum Peak kVAR",
    )
    max_peak_kw: confloat(ge=0.0) = Field(
        ...,
        description="Maximum peak active power consumption in kW.",
        title="Maximum Peak kW",
    )
    max_peak_kvar: confloat(ge=0.0) = Field(
        ...,
        description="Maximum peak reactive power consumption in kVAR.",
        title="Maximum Peak kVAR",
    )
    std_peak_kw: Union[float, str] = Field(
        ...,
        description="Standard deviation peak active power consumption in kW.",
        title="Standard Deviation Peak kW",
    )
    std_peak_kvar: Union[float, str] = Field(
        ...,
        description="Standard deviation peak reactive power consumption in kVAR.",
        title="Standard Deviation Peak kVAR",
    )


class DistributionSystemAssets(BaseModel):
    """
    Object capturing high level asset information.
    """

    transformers: Optional[List[TransformerItem]] = Field(
        None,
        description="Object capturing high level information about distribution transformers.",
        title="Distribution Transformers",
    )
    feeder_sections: Optional[List[FeederSectionItem]] = Field(
        None,
        description="High level information about feeder sections.",
        title="Distribution Feeder Sections",
    )
    capacitors: Optional[List[CapacitorItem]] = Field(
        None,
        description="Object representing high level information about capacitors.",
        title="Capacitors",
    )
    switches: Optional[List[SwitchItem]] = Field(
        None,
        description="High level information about switches present in the model.",
        title="Switches",
    )
    loads: Optional[List[LoadItem]] = Field(
        None, description="Represents high level load information.", title="Loads"
    )


class SnapshotCategory(Enum):
    """
    Snapshot category from which these metrics are generated.
    """

    NetPeakLoad = "NetPeakLoad"
    NetMinLoad = "NetMinLoad"
    BasePeakLoad = "BasePeakLoad"
    BaseMinLoad = "BaseMinLoad"


class VoltageMetric(BaseModel):
    """
    Summary of voltage metrics.
    """

    snapshot_category: SnapshotCategory = Field(
        ...,
        description="Snapshot category from which these metrics are generated.",
        title="Snapshot Category",
    )
    kv: confloat(ge=0.01) = Field(..., description="Voltage level in kV.", title="Voltage Level")
    num_phase: confloat(ge=1.0, le=3.0) = Field(
        ..., description="Number of phase.", title="Number of Phase"
    )
    avg_voltage_pu: confloat(le=2.0) = Field(
        ..., description="Average per unit voltage.", title="Average PU Voltage"
    )
    min_voltage_pu: confloat(le=2.0) = Field(
        ..., description="Minimum per unit voltage.", title="Minimum PU Voltage"
    )
    max_voltage_pu: confloat(le=2.0) = Field(
        ..., description="Maximum per unit voltage.", title="Maximum PU Voltage"
    )
    std_voltage_pu: Union[confloat(le=2.0), str] = Field(
        ...,
        description="Standard deviation per unit voltage.",
        title="Standard Deviation PU Voltage",
    )


class DehydrationMetadataV1(BaseModel):
    """
    Data representation after obfuscating distribution system model.
    """

    metadata: Metadata = Field(
        ...,
        description="Contains information about location, creation date and model year.",
        title="Metadata",
    )
    assets: DistributionSystemAssets = Field(
        ...,
        description="Object capturing high level asset information.",
        title="Distribution System Assets",
    )
    voltage_metrics: List[VoltageMetric] = Field(
        ...,
        description="High level information about voltage metrics.",
        title="Voltage Metrics",
    )
