# 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
from typing import Any, ClassVar, Dict, List, Optional, Union
from intervals_icu_client.models.bucket import Bucket
from intervals_icu_client.models.curve import Curve
from typing import Optional, Set
from typing_extensions import Self

class PowerVsHRPlot(BaseModel):
    """
    PowerVsHRPlot
    """ # noqa: E501
    bucket_size: Optional[StrictInt] = Field(default=None, alias="bucketSize")
    warmup: Optional[StrictInt] = None
    cooldown: Optional[StrictInt] = None
    elapsed_time: Optional[StrictInt] = Field(default=None, alias="elapsedTime")
    hr_lag: Optional[StrictInt] = Field(default=None, alias="hrLag")
    power_hr: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="powerHr")
    power_hr_first: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="powerHrFirst")
    power_hr_second: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="powerHrSecond")
    decoupling: Optional[Union[StrictFloat, StrictInt]] = None
    power_hr_z2: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="powerHrZ2")
    median_cadence_z2: Optional[StrictInt] = Field(default=None, alias="medianCadenceZ2")
    avg_cadence_z2: Optional[StrictInt] = Field(default=None, alias="avgCadenceZ2")
    hr_z2_bucket_count: Optional[StrictInt] = Field(default=None, alias="hrZ2BucketCount")
    start: Optional[StrictInt] = None
    mid: Optional[StrictInt] = None
    end: Optional[StrictInt] = None
    series: Optional[List[Bucket]] = None
    curves: Optional[List[Curve]] = None
    ratio_coefficients: Optional[List[Union[StrictFloat, StrictInt]]] = Field(default=None, alias="ratioCoefficients")
    __properties: ClassVar[List[str]] = ["bucketSize", "warmup", "cooldown", "elapsedTime", "hrLag", "powerHr", "powerHrFirst", "powerHrSecond", "decoupling", "powerHrZ2", "medianCadenceZ2", "avgCadenceZ2", "hrZ2BucketCount", "start", "mid", "end", "series", "curves", "ratioCoefficients"]

    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 PowerVsHRPlot 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 series (list)
        _items = []
        if self.series:
            for _item_series in self.series:
                if _item_series:
                    _items.append(_item_series.to_dict())
            _dict['series'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in curves (list)
        _items = []
        if self.curves:
            for _item_curves in self.curves:
                if _item_curves:
                    _items.append(_item_curves.to_dict())
            _dict['curves'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "bucketSize": obj.get("bucketSize"),
            "warmup": obj.get("warmup"),
            "cooldown": obj.get("cooldown"),
            "elapsedTime": obj.get("elapsedTime"),
            "hrLag": obj.get("hrLag"),
            "powerHr": obj.get("powerHr"),
            "powerHrFirst": obj.get("powerHrFirst"),
            "powerHrSecond": obj.get("powerHrSecond"),
            "decoupling": obj.get("decoupling"),
            "powerHrZ2": obj.get("powerHrZ2"),
            "medianCadenceZ2": obj.get("medianCadenceZ2"),
            "avgCadenceZ2": obj.get("avgCadenceZ2"),
            "hrZ2BucketCount": obj.get("hrZ2BucketCount"),
            "start": obj.get("start"),
            "mid": obj.get("mid"),
            "end": obj.get("end"),
            "series": [Bucket.from_dict(_item) for _item in obj["series"]] if obj.get("series") is not None else None,
            "curves": [Curve.from_dict(_item) for _item in obj["curves"]] if obj.get("curves") is not None else None,
            "ratioCoefficients": obj.get("ratioCoefficients")
        })
        return _obj


