# coding: utf-8

"""
    Rapidata Asset API

    The API for the Rapidata Asset service

    The version of the OpenAPI document: v1
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from rapidata.api_client.models.flow_item_state import FlowItemState
from typing import Optional, Set
from typing_extensions import Self

class GetFlowItemByIdEndpointOutput(BaseModel):
    """
    GetFlowItemByIdEndpointOutput
    """ # noqa: E501
    id: StrictStr = Field(description="The unique identifier of the flow item.")
    flow_id: StrictStr = Field(description="The ID of the flow this item belongs to.", alias="flowId")
    dataset_id: StrictStr = Field(description="The ID of the dataset used by this flow item.", alias="datasetId")
    workflow_id: Optional[StrictStr] = Field(default=None, description="The ID of the workflow created for this flow item.", alias="workflowId")
    state: FlowItemState
    context: Optional[StrictStr] = Field(default=None, description="Optional context associated with this flow item.")
    failure_message: Optional[StrictStr] = Field(default=None, description="The failure message if the flow item failed.", alias="failureMessage")
    expires_at: Optional[datetime] = Field(default=None, description="The expiration timestamp of the flow item.", alias="expiresAt")
    created_at: datetime = Field(description="The timestamp when the flow item was created.", alias="createdAt")
    started_at: Optional[datetime] = Field(default=None, description="The timestamp when the flow item started processing.", alias="startedAt")
    completed_at: Optional[datetime] = Field(default=None, description="The timestamp when the flow item completed.", alias="completedAt")
    failed_at: Optional[datetime] = Field(default=None, description="The timestamp when the flow item failed.", alias="failedAt")
    __properties: ClassVar[List[str]] = ["id", "flowId", "datasetId", "workflowId", "state", "context", "failureMessage", "expiresAt", "createdAt", "startedAt", "completedAt", "failedAt"]

    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 GetFlowItemByIdEndpointOutput 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,
        )
        # set to None if workflow_id (nullable) is None
        # and model_fields_set contains the field
        if self.workflow_id is None and "workflow_id" in self.model_fields_set:
            _dict['workflowId'] = None

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of GetFlowItemByIdEndpointOutput 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"),
            "flowId": obj.get("flowId"),
            "datasetId": obj.get("datasetId"),
            "workflowId": obj.get("workflowId"),
            "state": obj.get("state"),
            "context": obj.get("context"),
            "failureMessage": obj.get("failureMessage"),
            "expiresAt": obj.get("expiresAt"),
            "createdAt": obj.get("createdAt"),
            "startedAt": obj.get("startedAt"),
            "completedAt": obj.get("completedAt"),
            "failedAt": obj.get("failedAt")
        })
        return _obj


