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

from __future__ import annotations
from .dto_costanalyticitem import DtoCostAnalyticItem, DtoCostAnalyticItemTypedDict
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoGetDetailedCostAnalyticsResponseTypedDict(TypedDict):
    cost_analytics: NotRequired[List[DtoCostAnalyticItemTypedDict]]
    r"""Cost analytics array (flattened from nested structure)"""
    currency: NotRequired[str]
    end_time: NotRequired[str]
    margin: NotRequired[str]
    r"""Revenue - Cost"""
    margin_percent: NotRequired[str]
    r"""(Margin / Revenue) * 100"""
    roi: NotRequired[str]
    r"""(Revenue - Cost) / Cost"""
    roi_percent: NotRequired[str]
    r"""ROI * 100"""
    start_time: NotRequired[str]
    total_cost: NotRequired[str]
    total_revenue: NotRequired[str]
    r"""Derived metrics"""


class DtoGetDetailedCostAnalyticsResponse(BaseModel):
    cost_analytics: Optional[List[DtoCostAnalyticItem]] = None
    r"""Cost analytics array (flattened from nested structure)"""

    currency: Optional[str] = None

    end_time: Optional[str] = None

    margin: Optional[str] = None
    r"""Revenue - Cost"""

    margin_percent: Optional[str] = None
    r"""(Margin / Revenue) * 100"""

    roi: Optional[str] = None
    r"""(Revenue - Cost) / Cost"""

    roi_percent: Optional[str] = None
    r"""ROI * 100"""

    start_time: Optional[str] = None

    total_cost: Optional[str] = None

    total_revenue: Optional[str] = None
    r"""Derived metrics"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cost_analytics",
                "currency",
                "end_time",
                "margin",
                "margin_percent",
                "roi",
                "roi_percent",
                "start_time",
                "total_cost",
                "total_revenue",
            ]
        )
        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
