# 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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from skyledge_sdk.models.change_log import ChangeLog
from skyledge_sdk.models.model_property import ModelProperty
from skyledge_sdk.models.task_asset_response import TaskAssetResponse
from skyledge_sdk.models.task_event_response import TaskEventResponse
from skyledge_sdk.models.triggered_by import TriggeredBy
from typing import Optional, Set
from typing_extensions import Self

class TaskResponse(BaseModel):
    """
    TaskResponse
    """ # noqa: E501
    id: Optional[StrictStr] = None
    task_type_id: Optional[StrictStr] = Field(default=None, alias="taskTypeId")
    qualifier: Optional[StrictStr] = None
    title: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    event: Optional[TaskEventResponse] = None
    asset: Optional[TaskAssetResponse] = None
    attributes: Dict[str, Any]
    status: Optional[StrictStr] = None
    due_date: Optional[StrictStr] = Field(default=None, alias="dueDate")
    triggered_by: Optional[TriggeredBy] = Field(default=None, alias="triggeredBy")
    notes: Optional[StrictStr] = None
    created_at: Optional[StrictStr] = Field(default=None, alias="createdAt")
    last_modified_at: Optional[StrictStr] = Field(default=None, alias="lastModifiedAt")
    properties: List[ModelProperty]
    change_logs: Optional[List[ChangeLog]] = Field(default=None, alias="changeLogs")
    deleted_at: Optional[StrictStr] = Field(default=None, alias="deletedAt")
    deleted: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["id", "taskTypeId", "qualifier", "title", "description", "event", "asset", "attributes", "status", "dueDate", "triggeredBy", "notes", "createdAt", "lastModifiedAt", "properties", "changeLogs", "deletedAt", "deleted"]

    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 TaskResponse 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 event
        if self.event:
            _dict['event'] = self.event.to_dict()
        # override the default output from pydantic by calling `to_dict()` of asset
        if self.asset:
            _dict['asset'] = self.asset.to_dict()
        # override the default output from pydantic by calling `to_dict()` of triggered_by
        if self.triggered_by:
            _dict['triggeredBy'] = self.triggered_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in properties (list)
        _items = []
        if self.properties:
            for _item_properties in self.properties:
                if _item_properties:
                    _items.append(_item_properties.to_dict())
            _dict['properties'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in change_logs (list)
        _items = []
        if self.change_logs:
            for _item_change_logs in self.change_logs:
                if _item_change_logs:
                    _items.append(_item_change_logs.to_dict())
            _dict['changeLogs'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TaskResponse 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"),
            "taskTypeId": obj.get("taskTypeId"),
            "qualifier": obj.get("qualifier"),
            "title": obj.get("title"),
            "description": obj.get("description"),
            "event": TaskEventResponse.from_dict(obj["event"]) if obj.get("event") is not None else None,
            "asset": TaskAssetResponse.from_dict(obj["asset"]) if obj.get("asset") is not None else None,
            "attributes": obj.get("attributes"),
            "status": obj.get("status"),
            "dueDate": obj.get("dueDate"),
            "triggeredBy": TriggeredBy.from_dict(obj["triggeredBy"]) if obj.get("triggeredBy") is not None else None,
            "notes": obj.get("notes"),
            "createdAt": obj.get("createdAt"),
            "lastModifiedAt": obj.get("lastModifiedAt"),
            "properties": [ModelProperty.from_dict(_item) for _item in obj["properties"]] if obj.get("properties") is not None else None,
            "changeLogs": [ChangeLog.from_dict(_item) for _item in obj["changeLogs"]] if obj.get("changeLogs") is not None else None,
            "deletedAt": obj.get("deletedAt"),
            "deleted": obj.get("deleted")
        })
        return _obj


