# coding: utf-8

"""
    Skyledge API

    Sky Ledge is an operational insights platform that gives you the visibility and control you need to minimise inefficiencies, oversight, theft, and ultimately, unnecessary costs associated with your operations.

    The version of the OpenAPI document: 1.0.3
    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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from skyledge_sdk.models.control_room import ControlRoom
from skyledge_sdk.models.linked_asset_response import LinkedAssetResponse
from skyledge_sdk.models.linked_place_response import LinkedPlaceResponse
from typing import Optional, Set
from typing_extensions import Self

class EventResponse(BaseModel):
    """
    EventResponse
    """ # noqa: E501
    id: StrictStr
    event_type_id: StrictStr = Field(alias="eventTypeId")
    title: StrictStr
    description: StrictStr
    importance_level: StrictInt = Field(alias="importanceLevel")
    location: Optional[Dict[str, Any]] = None
    dynamic_attributes: Dict[str, Any] = Field(alias="dynamicAttributes")
    state: Optional[StrictStr] = None
    linked_assets: List[LinkedAssetResponse] = Field(alias="linkedAssets")
    linked_places: List[LinkedPlaceResponse] = Field(alias="linkedPlaces")
    qualifier: StrictStr
    external_urls: Dict[str, StrictStr] = Field(alias="externalUrls")
    created_at: StrictStr = Field(alias="createdAt")
    last_modified_at: StrictStr = Field(alias="lastModifiedAt")
    recorded_at: StrictStr = Field(alias="recordedAt")
    root_recorded_at: StrictStr = Field(alias="rootRecordedAt")
    control_rooms: Optional[List[ControlRoom]] = Field(default=None, alias="controlRooms")
    __properties: ClassVar[List[str]] = ["id", "eventTypeId", "title", "description", "importanceLevel", "location", "dynamicAttributes", "state", "linkedAssets", "linkedPlaces", "qualifier", "externalUrls", "createdAt", "lastModifiedAt", "recordedAt", "rootRecordedAt", "controlRooms"]

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

        if value not in set(['ACTIVE', 'COMPLETE', 'RESOLVED']):
            raise ValueError("must be one of enum values ('ACTIVE', 'COMPLETE', 'RESOLVED')")
        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 EventResponse 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 linked_assets (list)
        _items = []
        if self.linked_assets:
            for _item_linked_assets in self.linked_assets:
                if _item_linked_assets:
                    _items.append(_item_linked_assets.to_dict())
            _dict['linkedAssets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in linked_places (list)
        _items = []
        if self.linked_places:
            for _item_linked_places in self.linked_places:
                if _item_linked_places:
                    _items.append(_item_linked_places.to_dict())
            _dict['linkedPlaces'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in control_rooms (list)
        _items = []
        if self.control_rooms:
            for _item_control_rooms in self.control_rooms:
                if _item_control_rooms:
                    _items.append(_item_control_rooms.to_dict())
            _dict['controlRooms'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of EventResponse 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"),
            "eventTypeId": obj.get("eventTypeId"),
            "title": obj.get("title"),
            "description": obj.get("description"),
            "importanceLevel": obj.get("importanceLevel"),
            "location": obj.get("location"),
            "dynamicAttributes": obj.get("dynamicAttributes"),
            "state": obj.get("state"),
            "linkedAssets": [LinkedAssetResponse.from_dict(_item) for _item in obj["linkedAssets"]] if obj.get("linkedAssets") is not None else None,
            "linkedPlaces": [LinkedPlaceResponse.from_dict(_item) for _item in obj["linkedPlaces"]] if obj.get("linkedPlaces") is not None else None,
            "qualifier": obj.get("qualifier"),
            "externalUrls": obj.get("externalUrls"),
            "createdAt": obj.get("createdAt"),
            "lastModifiedAt": obj.get("lastModifiedAt"),
            "recordedAt": obj.get("recordedAt"),
            "rootRecordedAt": obj.get("rootRecordedAt"),
            "controlRooms": [ControlRoom.from_dict(_item) for _item in obj["controlRooms"]] if obj.get("controlRooms") is not None else None
        })
        return _obj


