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

class SharedEvent(BaseModel):
    """
    SharedEvent
    """ # noqa: E501
    id: Optional[StrictInt] = None
    external_id: Optional[StrictStr] = None
    athlete_id: Optional[StrictStr] = None
    category: Optional[StrictStr] = None
    types: Optional[List[StrictStr]] = None
    name: Optional[StrictStr] = None
    start_date_local: Optional[StrictStr] = None
    visibility: Optional[StrictStr] = None
    chat_id: Optional[StrictInt] = None
    description: Optional[StrictStr] = None
    website: Optional[StrictStr] = None
    closing_date_local: Optional[StrictStr] = None
    location: Optional[StrictStr] = None
    address: Optional[StrictStr] = None
    country: Optional[StrictStr] = None
    region: Optional[StrictStr] = None
    lat: Optional[Union[StrictFloat, StrictInt]] = None
    lon: Optional[Union[StrictFloat, StrictInt]] = None
    route_file: Optional[StrictStr] = None
    polyline: Optional[StrictStr] = None
    usage_count: Optional[StrictInt] = None
    owner: Optional[AthleteSearchResult] = None
    __properties: ClassVar[List[str]] = ["id", "external_id", "athlete_id", "category", "types", "name", "start_date_local", "visibility", "chat_id", "description", "website", "closing_date_local", "location", "address", "country", "region", "lat", "lon", "route_file", "polyline", "usage_count", "owner"]

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

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

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

        for i in value:
            if i not in set(['Ride', 'Run', 'Swim', 'WeightTraining', 'Hike', 'Walk', 'AlpineSki', 'BackcountrySki', 'Badminton', 'Canoeing', 'Crossfit', 'EBikeRide', 'EMountainBikeRide', 'Elliptical', 'Golf', 'GravelRide', 'TrackRide', 'Handcycle', 'HighIntensityIntervalTraining', 'Hockey', 'IceSkate', 'InlineSkate', 'Kayaking', 'Kitesurf', 'MountainBikeRide', 'NordicSki', 'OpenWaterSwim', 'Padel', 'Pilates', 'Pickleball', 'Racquetball', 'Rugby', 'RockClimbing', 'RollerSki', 'Rowing', 'Sail', 'Skateboard', 'Snowboard', 'Snowshoe', 'Soccer', 'Squash', 'StairStepper', 'StandUpPaddling', 'Surfing', 'TableTennis', 'Tennis', 'TrailRun', 'Transition', 'Velomobile', 'VirtualRide', 'VirtualRow', 'VirtualRun', 'VirtualSki', 'WaterSport', 'Wheelchair', 'Windsurf', 'Workout', 'Yoga', 'Other']):
                raise ValueError("each list item must be one of ('Ride', 'Run', 'Swim', 'WeightTraining', 'Hike', 'Walk', 'AlpineSki', 'BackcountrySki', 'Badminton', 'Canoeing', 'Crossfit', 'EBikeRide', 'EMountainBikeRide', 'Elliptical', 'Golf', 'GravelRide', 'TrackRide', 'Handcycle', 'HighIntensityIntervalTraining', 'Hockey', 'IceSkate', 'InlineSkate', 'Kayaking', 'Kitesurf', 'MountainBikeRide', 'NordicSki', 'OpenWaterSwim', 'Padel', 'Pilates', 'Pickleball', 'Racquetball', 'Rugby', 'RockClimbing', 'RollerSki', 'Rowing', 'Sail', 'Skateboard', 'Snowboard', 'Snowshoe', 'Soccer', 'Squash', 'StairStepper', 'StandUpPaddling', 'Surfing', 'TableTennis', 'Tennis', 'TrailRun', 'Transition', 'Velomobile', 'VirtualRide', 'VirtualRow', 'VirtualRun', 'VirtualSki', 'WaterSport', 'Wheelchair', 'Windsurf', 'Workout', 'Yoga', 'Other')")
        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(['PUBLIC', 'GROUP']):
            raise ValueError("must be one of enum values ('PUBLIC', 'GROUP')")
        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 SharedEvent 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 owner
        if self.owner:
            _dict['owner'] = self.owner.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SharedEvent 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"),
            "external_id": obj.get("external_id"),
            "athlete_id": obj.get("athlete_id"),
            "category": obj.get("category"),
            "types": obj.get("types"),
            "name": obj.get("name"),
            "start_date_local": obj.get("start_date_local"),
            "visibility": obj.get("visibility"),
            "chat_id": obj.get("chat_id"),
            "description": obj.get("description"),
            "website": obj.get("website"),
            "closing_date_local": obj.get("closing_date_local"),
            "location": obj.get("location"),
            "address": obj.get("address"),
            "country": obj.get("country"),
            "region": obj.get("region"),
            "lat": obj.get("lat"),
            "lon": obj.get("lon"),
            "route_file": obj.get("route_file"),
            "polyline": obj.get("polyline"),
            "usage_count": obj.get("usage_count"),
            "owner": AthleteSearchResult.from_dict(obj["owner"]) if obj.get("owner") is not None else None
        })
        return _obj


