"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .alertsettings import AlertSettings, AlertSettingsTypedDict
from .meter_filter import MeterFilter, MeterFilterTypedDict
from .reportingunit import ReportingUnit, ReportingUnitTypedDict
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoUpdateFeatureRequestTypedDict(TypedDict):
    alert_settings: NotRequired[AlertSettingsTypedDict]
    description: NotRequired[str]
    filters: NotRequired[List[MeterFilterTypedDict]]
    group_id: NotRequired[str]
    r"""GroupID is the id of the group to assign the feature to. Pass empty string to clear."""
    metadata: NotRequired[Dict[str, str]]
    name: NotRequired[str]
    reporting_unit: NotRequired[ReportingUnitTypedDict]
    unit_plural: NotRequired[str]
    unit_singular: NotRequired[str]


class DtoUpdateFeatureRequest(BaseModel):
    alert_settings: Optional[AlertSettings] = None

    description: Optional[str] = None

    filters: Optional[List[MeterFilter]] = None

    group_id: Optional[str] = None
    r"""GroupID is the id of the group to assign the feature to. Pass empty string to clear."""

    metadata: Optional[Dict[str, str]] = None

    name: Optional[str] = None

    reporting_unit: Optional[ReportingUnit] = None

    unit_plural: Optional[str] = None

    unit_singular: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "alert_settings",
                "description",
                "filters",
                "group_id",
                "metadata",
                "name",
                "reporting_unit",
                "unit_plural",
                "unit_singular",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
