# 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.category_summary import CategorySummary
from typing import Optional, Set
from typing_extensions import Self

class SummaryWithCats(BaseModel):
    """
    SummaryWithCats
    """ # noqa: E501
    count: Optional[StrictInt] = None
    time: Optional[StrictInt] = None
    moving_time: Optional[StrictInt] = None
    elapsed_time: Optional[StrictInt] = None
    calories: Optional[StrictInt] = None
    total_elevation_gain: Optional[Union[StrictFloat, StrictInt]] = None
    training_load: Optional[StrictInt] = None
    srpe: Optional[StrictInt] = None
    distance: Optional[Union[StrictFloat, StrictInt]] = None
    eftp: Optional[Union[StrictFloat, StrictInt]] = None
    eftp_per_kg: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="eftpPerKg")
    var_date: Optional[StrictStr] = Field(default=None, alias="date")
    athlete_id: Optional[StrictStr] = None
    athlete_name: Optional[StrictStr] = None
    email: Optional[StrictStr] = None
    external_id: Optional[StrictStr] = None
    fitness: Optional[Union[StrictFloat, StrictInt]] = None
    fatigue: Optional[Union[StrictFloat, StrictInt]] = None
    form: Optional[Union[StrictFloat, StrictInt]] = None
    ramp_rate: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="rampRate")
    weight: Optional[Union[StrictFloat, StrictInt]] = None
    time_in_zones: Optional[List[StrictInt]] = Field(default=None, alias="timeInZones")
    time_in_zones_tot: Optional[StrictInt] = Field(default=None, alias="timeInZonesTot")
    by_category: Optional[List[CategorySummary]] = Field(default=None, alias="byCategory")
    most_recent_wellness_id: Optional[StrictStr] = Field(default=None, alias="mostRecentWellnessId")
    __properties: ClassVar[List[str]] = ["count", "time", "moving_time", "elapsed_time", "calories", "total_elevation_gain", "training_load", "srpe", "distance", "eftp", "eftpPerKg", "date", "athlete_id", "athlete_name", "email", "external_id", "fitness", "fatigue", "form", "rampRate", "weight", "timeInZones", "timeInZonesTot", "byCategory", "mostRecentWellnessId"]

    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 SummaryWithCats 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 by_category (list)
        _items = []
        if self.by_category:
            for _item_by_category in self.by_category:
                if _item_by_category:
                    _items.append(_item_by_category.to_dict())
            _dict['byCategory'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "count": obj.get("count"),
            "time": obj.get("time"),
            "moving_time": obj.get("moving_time"),
            "elapsed_time": obj.get("elapsed_time"),
            "calories": obj.get("calories"),
            "total_elevation_gain": obj.get("total_elevation_gain"),
            "training_load": obj.get("training_load"),
            "srpe": obj.get("srpe"),
            "distance": obj.get("distance"),
            "eftp": obj.get("eftp"),
            "eftpPerKg": obj.get("eftpPerKg"),
            "date": obj.get("date"),
            "athlete_id": obj.get("athlete_id"),
            "athlete_name": obj.get("athlete_name"),
            "email": obj.get("email"),
            "external_id": obj.get("external_id"),
            "fitness": obj.get("fitness"),
            "fatigue": obj.get("fatigue"),
            "form": obj.get("form"),
            "rampRate": obj.get("rampRate"),
            "weight": obj.get("weight"),
            "timeInZones": obj.get("timeInZones"),
            "timeInZonesTot": obj.get("timeInZonesTot"),
            "byCategory": [CategorySummary.from_dict(_item) for _item in obj["byCategory"]] if obj.get("byCategory") is not None else None,
            "mostRecentWellnessId": obj.get("mostRecentWellnessId")
        })
        return _obj


