# coding: utf-8

"""
    Kestra EE

    All API operations, except for Superadmin-only endpoints, require a tenant identifier in the HTTP path.<br/> Endpoints designated as Superadmin-only are not tenant-scoped.

    The version of the OpenAPI document: 1.1.4
    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, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kestrapy.models.execution_kind import ExecutionKind
from kestrapy.models.level import Level
from typing import Optional, Set
from typing_extensions import Self

class LogEntry(BaseModel):
    """
    LogEntry
    """ # noqa: E501
    namespace: StrictStr
    flow_id: StrictStr = Field(alias="flowId")
    task_id: Optional[StrictStr] = Field(default=None, alias="taskId")
    execution_id: Optional[StrictStr] = Field(default=None, alias="executionId")
    task_run_id: Optional[StrictStr] = Field(default=None, alias="taskRunId")
    attempt_number: Optional[StrictInt] = Field(default=None, alias="attemptNumber")
    trigger_id: Optional[StrictStr] = Field(default=None, alias="triggerId")
    timestamp: Optional[datetime] = None
    level: Optional[Level] = None
    thread: Optional[StrictStr] = None
    message: Optional[StrictStr] = None
    deleted: StrictBool
    execution_kind: Optional[ExecutionKind] = Field(default=None, alias="executionKind")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["namespace", "flowId", "taskId", "executionId", "taskRunId", "attemptNumber", "triggerId", "timestamp", "level", "thread", "message", "deleted", "executionKind"]

    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 LogEntry 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        # set to None if task_id (nullable) is None
        # and model_fields_set contains the field
        if self.task_id is None and "task_id" in self.model_fields_set:
            _dict['taskId'] = None

        # set to None if execution_id (nullable) is None
        # and model_fields_set contains the field
        if self.execution_id is None and "execution_id" in self.model_fields_set:
            _dict['executionId'] = None

        # set to None if task_run_id (nullable) is None
        # and model_fields_set contains the field
        if self.task_run_id is None and "task_run_id" in self.model_fields_set:
            _dict['taskRunId'] = None

        # set to None if attempt_number (nullable) is None
        # and model_fields_set contains the field
        if self.attempt_number is None and "attempt_number" in self.model_fields_set:
            _dict['attemptNumber'] = None

        # set to None if trigger_id (nullable) is None
        # and model_fields_set contains the field
        if self.trigger_id is None and "trigger_id" in self.model_fields_set:
            _dict['triggerId'] = None

        # set to None if execution_kind (nullable) is None
        # and model_fields_set contains the field
        if self.execution_kind is None and "execution_kind" in self.model_fields_set:
            _dict['executionKind'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of LogEntry from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "namespace": obj.get("namespace"),
            "flowId": obj.get("flowId"),
            "taskId": obj.get("taskId"),
            "executionId": obj.get("executionId"),
            "taskRunId": obj.get("taskRunId"),
            "attemptNumber": obj.get("attemptNumber"),
            "triggerId": obj.get("triggerId"),
            "timestamp": obj.get("timestamp"),
            "level": obj.get("level"),
            "thread": obj.get("thread"),
            "message": obj.get("message"),
            "deleted": obj.get("deleted"),
            "executionKind": obj.get("executionKind")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


