# 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 intervals_icu_client.models.push_error import PushError
from intervals_icu_client.models.workout import Workout
from typing import Optional, Set
from typing_extensions import Self

class EventEx(BaseModel):
    """
    EventEx
    """ # noqa: E501
    id: Optional[StrictInt] = None
    start_date_local: Optional[StrictStr] = None
    icu_training_load: Optional[StrictInt] = None
    icu_atl: Optional[Union[StrictFloat, StrictInt]] = None
    icu_ctl: Optional[Union[StrictFloat, StrictInt]] = None
    type: Optional[StrictStr] = None
    carbs_used: Optional[StrictInt] = None
    ss_p_max: Optional[Union[StrictFloat, StrictInt]] = None
    ss_w_prime: Optional[Union[StrictFloat, StrictInt]] = None
    ss_cp: Optional[Union[StrictFloat, StrictInt]] = None
    calendar_id: Optional[StrictInt] = None
    uid: Optional[StrictStr] = None
    athlete_id: Optional[StrictStr] = None
    category: Optional[StrictStr] = None
    end_date_local: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    indoor: Optional[StrictBool] = None
    color: Optional[StrictStr] = None
    moving_time: Optional[StrictInt] = None
    icu_ftp: Optional[StrictInt] = None
    w_prime: Optional[StrictInt] = None
    p_max: Optional[StrictInt] = None
    atl_days: Optional[StrictInt] = None
    ctl_days: Optional[StrictInt] = None
    updated: Optional[datetime] = None
    not_on_fitness_chart: Optional[StrictBool] = None
    show_as_note: Optional[StrictBool] = None
    show_on_ctl_line: Optional[StrictBool] = None
    for_week: Optional[StrictBool] = None
    target: Optional[StrictStr] = None
    joules: Optional[StrictInt] = None
    joules_above_ftp: Optional[StrictInt] = None
    workout_doc: Optional[Dict[str, Dict[str, Any]]] = None
    push_errors: Optional[List[PushError]] = None
    athlete_cannot_edit: Optional[StrictBool] = None
    hide_from_athlete: Optional[StrictBool] = None
    structure_read_only: Optional[StrictBool] = None
    created_by_id: Optional[StrictStr] = None
    shared_event_id: Optional[StrictInt] = None
    entered: Optional[StrictBool] = None
    carbs_per_hour: Optional[StrictInt] = None
    sub_type: Optional[StrictStr] = None
    distance: Optional[Union[StrictFloat, StrictInt]] = None
    tags: Optional[List[StrictStr]] = None
    attachments: Optional[List[Attachment]] = None
    oauth_client_id: Optional[StrictInt] = None
    external_id: Optional[StrictStr] = None
    load_target: Optional[StrictInt] = None
    time_target: Optional[StrictInt] = None
    distance_target: Optional[Union[StrictFloat, StrictInt]] = None
    plan_athlete_id: Optional[StrictStr] = None
    plan_folder_id: Optional[StrictInt] = None
    plan_workout_id: Optional[StrictInt] = None
    plan_applied: Optional[datetime] = None
    workout: Optional[Workout] = None
    file_contents: Optional[StrictStr] = None
    file_contents_base64: Optional[StrictStr] = None
    filename: Optional[StrictStr] = None
    icu_intensity: Optional[Union[StrictFloat, StrictInt]] = None
    strain_score: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["id", "start_date_local", "icu_training_load", "icu_atl", "icu_ctl", "type", "carbs_used", "ss_p_max", "ss_w_prime", "ss_cp", "calendar_id", "uid", "athlete_id", "category", "end_date_local", "name", "description", "indoor", "color", "moving_time", "icu_ftp", "w_prime", "p_max", "atl_days", "ctl_days", "updated", "not_on_fitness_chart", "show_as_note", "show_on_ctl_line", "for_week", "target", "joules", "joules_above_ftp", "workout_doc", "push_errors", "athlete_cannot_edit", "hide_from_athlete", "structure_read_only", "created_by_id", "shared_event_id", "entered", "carbs_per_hour", "sub_type", "distance", "tags", "attachments", "oauth_client_id", "external_id", "load_target", "time_target", "distance_target", "plan_athlete_id", "plan_folder_id", "plan_workout_id", "plan_applied", "workout", "file_contents", "file_contents_base64", "filename", "icu_intensity", "strain_score"]

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

        if value not in set(['WORKOUT', 'RACE_A', 'RACE_B', 'RACE_C', 'NOTE', 'PLAN', 'HOLIDAY', 'SICK', 'INJURED', 'SET_EFTP', 'FITNESS_DAYS', 'SEASON_START', 'TARGET', 'SET_FITNESS']):
            raise ValueError("must be one of enum values ('WORKOUT', 'RACE_A', 'RACE_B', 'RACE_C', 'NOTE', 'PLAN', 'HOLIDAY', 'SICK', 'INJURED', 'SET_EFTP', 'FITNESS_DAYS', 'SEASON_START', 'TARGET', 'SET_FITNESS')")
        return value

    @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('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 EventEx 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 push_errors (list)
        _items = []
        if self.push_errors:
            for _item_push_errors in self.push_errors:
                if _item_push_errors:
                    _items.append(_item_push_errors.to_dict())
            _dict['push_errors'] = _items
        # 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
        # override the default output from pydantic by calling `to_dict()` of workout
        if self.workout:
            _dict['workout'] = self.workout.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of EventEx 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"),
            "start_date_local": obj.get("start_date_local"),
            "icu_training_load": obj.get("icu_training_load"),
            "icu_atl": obj.get("icu_atl"),
            "icu_ctl": obj.get("icu_ctl"),
            "type": obj.get("type"),
            "carbs_used": obj.get("carbs_used"),
            "ss_p_max": obj.get("ss_p_max"),
            "ss_w_prime": obj.get("ss_w_prime"),
            "ss_cp": obj.get("ss_cp"),
            "calendar_id": obj.get("calendar_id"),
            "uid": obj.get("uid"),
            "athlete_id": obj.get("athlete_id"),
            "category": obj.get("category"),
            "end_date_local": obj.get("end_date_local"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "indoor": obj.get("indoor"),
            "color": obj.get("color"),
            "moving_time": obj.get("moving_time"),
            "icu_ftp": obj.get("icu_ftp"),
            "w_prime": obj.get("w_prime"),
            "p_max": obj.get("p_max"),
            "atl_days": obj.get("atl_days"),
            "ctl_days": obj.get("ctl_days"),
            "updated": obj.get("updated"),
            "not_on_fitness_chart": obj.get("not_on_fitness_chart"),
            "show_as_note": obj.get("show_as_note"),
            "show_on_ctl_line": obj.get("show_on_ctl_line"),
            "for_week": obj.get("for_week"),
            "target": obj.get("target"),
            "joules": obj.get("joules"),
            "joules_above_ftp": obj.get("joules_above_ftp"),
            "workout_doc": obj.get("workout_doc"),
            "push_errors": [PushError.from_dict(_item) for _item in obj["push_errors"]] if obj.get("push_errors") is not None else None,
            "athlete_cannot_edit": obj.get("athlete_cannot_edit"),
            "hide_from_athlete": obj.get("hide_from_athlete"),
            "structure_read_only": obj.get("structure_read_only"),
            "created_by_id": obj.get("created_by_id"),
            "shared_event_id": obj.get("shared_event_id"),
            "entered": obj.get("entered"),
            "carbs_per_hour": obj.get("carbs_per_hour"),
            "sub_type": obj.get("sub_type"),
            "distance": obj.get("distance"),
            "tags": obj.get("tags"),
            "attachments": [Attachment.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "oauth_client_id": obj.get("oauth_client_id"),
            "external_id": obj.get("external_id"),
            "load_target": obj.get("load_target"),
            "time_target": obj.get("time_target"),
            "distance_target": obj.get("distance_target"),
            "plan_athlete_id": obj.get("plan_athlete_id"),
            "plan_folder_id": obj.get("plan_folder_id"),
            "plan_workout_id": obj.get("plan_workout_id"),
            "plan_applied": obj.get("plan_applied"),
            "workout": Workout.from_dict(obj["workout"]) if obj.get("workout") is not None else None,
            "file_contents": obj.get("file_contents"),
            "file_contents_base64": obj.get("file_contents_base64"),
            "filename": obj.get("filename"),
            "icu_intensity": obj.get("icu_intensity"),
            "strain_score": obj.get("strain_score")
        })
        return _obj


