# coding: utf-8

"""
    Intervals.icu API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: v1.0.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from intervals_icu_client.models.activity_filter import ActivityFilter
from intervals_icu_client.models.plot import Plot
from intervals_icu_client.models.power_model import PowerModel
from intervals_icu_client.models.rank import Rank
from typing import Optional, Set
from typing_extensions import Self

class PowerCurve(BaseModel):
    """
    PowerCurve
    """ # noqa: E501
    id: Optional[StrictStr] = None
    after_kj: Optional[StrictInt] = None
    filters: Optional[List[ActivityFilter]] = None
    label: Optional[StrictStr] = None
    filter_label: Optional[StrictStr] = None
    percentile: Optional[Union[StrictFloat, StrictInt]] = None
    start_date_local: Optional[StrictStr] = None
    end_date_local: Optional[StrictStr] = None
    days: Optional[StrictInt] = None
    moving_time: Optional[StrictInt] = None
    training_load: Optional[StrictInt] = None
    weight: Optional[Union[StrictFloat, StrictInt]] = None
    secs: Optional[List[StrictInt]] = None
    values: Optional[List[StrictInt]] = None
    submax_values: Optional[List[List[StrictInt]]] = None
    submax_activity_id: Optional[List[List[StrictStr]]] = None
    start_index: Optional[List[StrictInt]] = None
    end_index: Optional[List[StrictInt]] = None
    activity_id: Optional[List[StrictStr]] = None
    watts_per_kg: Optional[List[Union[StrictFloat, StrictInt]]] = None
    wkg_activity_id: Optional[List[StrictStr]] = None
    submax_watts_per_kg: Optional[List[List[Union[StrictFloat, StrictInt]]]] = None
    submax_wkg_activity_id: Optional[List[List[StrictStr]]] = None
    power_models: Optional[List[PowerModel]] = Field(default=None, alias="powerModels")
    ranks: Optional[Dict[str, Rank]] = None
    map_plot: Optional[Plot] = Field(default=None, alias="mapPlot")
    stream_type: Optional[StrictStr] = None
    stream_name: Optional[StrictStr] = None
    watts: Optional[List[StrictInt]] = None
    vo2max_5m: Optional[Union[StrictFloat, StrictInt]] = None
    compound_score_5m: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["id", "after_kj", "filters", "label", "filter_label", "percentile", "start_date_local", "end_date_local", "days", "moving_time", "training_load", "weight", "secs", "values", "submax_values", "submax_activity_id", "start_index", "end_index", "activity_id", "watts_per_kg", "wkg_activity_id", "submax_watts_per_kg", "submax_wkg_activity_id", "powerModels", "ranks", "mapPlot", "stream_type", "stream_name", "watts", "vo2max_5m", "compound_score_5m"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PowerCurve from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in filters (list)
        _items = []
        if self.filters:
            for _item_filters in self.filters:
                if _item_filters:
                    _items.append(_item_filters.to_dict())
            _dict['filters'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in power_models (list)
        _items = []
        if self.power_models:
            for _item_power_models in self.power_models:
                if _item_power_models:
                    _items.append(_item_power_models.to_dict())
            _dict['powerModels'] = _items
        # override the default output from pydantic by calling `to_dict()` of each value in ranks (dict)
        _field_dict = {}
        if self.ranks:
            for _key_ranks in self.ranks:
                if self.ranks[_key_ranks]:
                    _field_dict[_key_ranks] = self.ranks[_key_ranks].to_dict()
            _dict['ranks'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of map_plot
        if self.map_plot:
            _dict['mapPlot'] = self.map_plot.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PowerCurve from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "after_kj": obj.get("after_kj"),
            "filters": [ActivityFilter.from_dict(_item) for _item in obj["filters"]] if obj.get("filters") is not None else None,
            "label": obj.get("label"),
            "filter_label": obj.get("filter_label"),
            "percentile": obj.get("percentile"),
            "start_date_local": obj.get("start_date_local"),
            "end_date_local": obj.get("end_date_local"),
            "days": obj.get("days"),
            "moving_time": obj.get("moving_time"),
            "training_load": obj.get("training_load"),
            "weight": obj.get("weight"),
            "secs": obj.get("secs"),
            "values": obj.get("values"),
            "submax_values": obj.get("submax_values"),
            "submax_activity_id": obj.get("submax_activity_id"),
            "start_index": obj.get("start_index"),
            "end_index": obj.get("end_index"),
            "activity_id": obj.get("activity_id"),
            "watts_per_kg": obj.get("watts_per_kg"),
            "wkg_activity_id": obj.get("wkg_activity_id"),
            "submax_watts_per_kg": obj.get("submax_watts_per_kg"),
            "submax_wkg_activity_id": obj.get("submax_wkg_activity_id"),
            "powerModels": [PowerModel.from_dict(_item) for _item in obj["powerModels"]] if obj.get("powerModels") is not None else None,
            "ranks": dict(
                (_k, Rank.from_dict(_v))
                for _k, _v in obj["ranks"].items()
            )
            if obj.get("ranks") is not None
            else None,
            "mapPlot": Plot.from_dict(obj["mapPlot"]) if obj.get("mapPlot") is not None else None,
            "stream_type": obj.get("stream_type"),
            "stream_name": obj.get("stream_name"),
            "watts": obj.get("watts"),
            "vo2max_5m": obj.get("vo2max_5m"),
            "compound_score_5m": obj.get("compound_score_5m")
        })
        return _obj


