# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from intervals_icu_client.models.athlete_search_result import AthleteSearchResult
from typing import Optional, Set
from typing_extensions import Self

class NewCustomItem(BaseModel):
    """
    NewCustomItem
    """ # noqa: E501
    id: Optional[StrictInt] = None
    athlete_id: Optional[StrictStr] = None
    type: Optional[StrictStr] = None
    visibility: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    image: Optional[StrictStr] = None
    content: Optional[Dict[str, Dict[str, Any]]] = None
    usage_count: Optional[StrictInt] = None
    index: Optional[StrictInt] = None
    hide_script: Optional[StrictBool] = None
    hidden_by_id: Optional[StrictStr] = None
    updated: Optional[datetime] = None
    from_athlete: Optional[AthleteSearchResult] = None
    from_id: Optional[StrictInt] = None
    required_items_created: Optional[List[NewCustomItem]] = None
    __properties: ClassVar[List[str]] = ["id", "athlete_id", "type", "visibility", "name", "description", "image", "content", "usage_count", "index", "hide_script", "hidden_by_id", "updated", "from_athlete", "from_id", "required_items_created"]

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

        if value not in set(['FITNESS_CHART', 'TRACE_CHART', 'INPUT_FIELD', 'ACTIVITY_FIELD', 'INTERVAL_FIELD', 'ACTIVITY_STREAM', 'ACTIVITY_CHART', 'ACTIVITY_HISTOGRAM', 'ACTIVITY_HEATMAP', 'ACTIVITY_MAP', 'ACTIVITY_PANEL', 'ZONES']):
            raise ValueError("must be one of enum values ('FITNESS_CHART', 'TRACE_CHART', 'INPUT_FIELD', 'ACTIVITY_FIELD', 'INTERVAL_FIELD', 'ACTIVITY_STREAM', 'ACTIVITY_CHART', 'ACTIVITY_HISTOGRAM', 'ACTIVITY_HEATMAP', 'ACTIVITY_MAP', 'ACTIVITY_PANEL', 'ZONES')")
        return value

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

        if value not in set(['PRIVATE', 'FOLLOWERS', 'PUBLIC']):
            raise ValueError("must be one of enum values ('PRIVATE', 'FOLLOWERS', 'PUBLIC')")
        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 NewCustomItem 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 from_athlete
        if self.from_athlete:
            _dict['from_athlete'] = self.from_athlete.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in required_items_created (list)
        _items = []
        if self.required_items_created:
            for _item_required_items_created in self.required_items_created:
                if _item_required_items_created:
                    _items.append(_item_required_items_created.to_dict())
            _dict['required_items_created'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of NewCustomItem 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"),
            "athlete_id": obj.get("athlete_id"),
            "type": obj.get("type"),
            "visibility": obj.get("visibility"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "image": obj.get("image"),
            "content": obj.get("content"),
            "usage_count": obj.get("usage_count"),
            "index": obj.get("index"),
            "hide_script": obj.get("hide_script"),
            "hidden_by_id": obj.get("hidden_by_id"),
            "updated": obj.get("updated"),
            "from_athlete": AthleteSearchResult.from_dict(obj["from_athlete"]) if obj.get("from_athlete") is not None else None,
            "from_id": obj.get("from_id"),
            "required_items_created": [NewCustomItem.from_dict(_item) for _item in obj["required_items_created"]] if obj.get("required_items_created") is not None else None
        })
        return _obj

# TODO: Rewrite to not use raise_errors
NewCustomItem.model_rebuild(raise_errors=False)

