# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from intervals_icu_client.models.attachment import Attachment
from typing import Optional, Set
from typing_extensions import Self

class Workout(BaseModel):
    """
    Workout
    """ # noqa: E501
    athlete_id: Optional[StrictStr] = None
    id: Optional[StrictInt] = None
    icu_training_load: Optional[StrictInt] = None
    name: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    type: Optional[StrictStr] = None
    indoor: Optional[StrictBool] = None
    color: Optional[StrictStr] = None
    moving_time: Optional[StrictInt] = None
    updated: Optional[datetime] = None
    joules: Optional[StrictInt] = None
    joules_above_ftp: Optional[StrictInt] = None
    workout_doc: Optional[Dict[str, Dict[str, Any]]] = None
    folder_id: Optional[StrictInt] = None
    day: Optional[StrictInt] = None
    days: Optional[StrictInt] = None
    plan_applied: Optional[datetime] = None
    hide_from_athlete: Optional[StrictBool] = None
    target: Optional[StrictStr] = None
    targets: Optional[List[StrictStr]] = None
    carbs_per_hour: Optional[StrictInt] = None
    tags: Optional[List[StrictStr]] = None
    attachments: Optional[List[Attachment]] = None
    time: Optional[StrictStr] = None
    sub_type: Optional[StrictStr] = None
    for_week: Optional[StrictBool] = None
    distance: Optional[Union[StrictFloat, StrictInt]] = None
    icu_intensity: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["athlete_id", "id", "icu_training_load", "name", "description", "type", "indoor", "color", "moving_time", "updated", "joules", "joules_above_ftp", "workout_doc", "folder_id", "day", "days", "plan_applied", "hide_from_athlete", "target", "targets", "carbs_per_hour", "tags", "attachments", "time", "sub_type", "for_week", "distance", "icu_intensity"]

    @field_validator('target')
    def target_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['AUTO', 'POWER', 'HR', 'PACE']):
            raise ValueError("must be one of enum values ('AUTO', 'POWER', 'HR', 'PACE')")
        return value

    @field_validator('targets')
    def targets_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['AUTO', 'POWER', 'HR', 'PACE']):
                raise ValueError("each list item must be one of ('AUTO', 'POWER', 'HR', 'PACE')")
        return value

    @field_validator('sub_type')
    def sub_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['NONE', 'COMMUTE', 'WARMUP', 'COOLDOWN', 'RACE']):
            raise ValueError("must be one of enum values ('NONE', 'COMMUTE', 'WARMUP', 'COOLDOWN', 'RACE')")
        return value

    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 Workout 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 attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "athlete_id": obj.get("athlete_id"),
            "id": obj.get("id"),
            "icu_training_load": obj.get("icu_training_load"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "type": obj.get("type"),
            "indoor": obj.get("indoor"),
            "color": obj.get("color"),
            "moving_time": obj.get("moving_time"),
            "updated": obj.get("updated"),
            "joules": obj.get("joules"),
            "joules_above_ftp": obj.get("joules_above_ftp"),
            "workout_doc": obj.get("workout_doc"),
            "folder_id": obj.get("folder_id"),
            "day": obj.get("day"),
            "days": obj.get("days"),
            "plan_applied": obj.get("plan_applied"),
            "hide_from_athlete": obj.get("hide_from_athlete"),
            "target": obj.get("target"),
            "targets": obj.get("targets"),
            "carbs_per_hour": obj.get("carbs_per_hour"),
            "tags": obj.get("tags"),
            "attachments": [Attachment.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "time": obj.get("time"),
            "sub_type": obj.get("sub_type"),
            "for_week": obj.get("for_week"),
            "distance": obj.get("distance"),
            "icu_intensity": obj.get("icu_intensity")
        })
        return _obj


