# coding: utf-8

"""
    Agent Service

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from asteroid_odyssey.models.agents_execution_comment import AgentsExecutionComment
from asteroid_odyssey.models.agents_execution_execution_result import AgentsExecutionExecutionResult
from asteroid_odyssey.models.agents_execution_human_label import AgentsExecutionHumanLabel
from asteroid_odyssey.models.agents_execution_status import AgentsExecutionStatus
from asteroid_odyssey.models.agents_execution_trigger_context import AgentsExecutionTriggerContext
from typing import Optional, Set
from typing_extensions import Self

class AgentsExecutionListItem(BaseModel):
    """
    Represents a single execution in a list view
    """ # noqa: E501
    id: StrictStr = Field(description="The unique identifier of the execution")
    agent_id: StrictStr = Field(description="The ID of the agent that was executed", alias="agentId")
    workflow_id: StrictStr = Field(description="The ID of the workflow that was executed", alias="workflowId")
    status: AgentsExecutionStatus = Field(description="The current status of the execution")
    created_at: datetime = Field(description="When the execution was created", alias="createdAt")
    terminal_at: Optional[datetime] = Field(default=None, description="When the execution reached a terminal state (if applicable)", alias="terminalAt")
    organization_id: StrictStr = Field(description="The organization this execution belongs to", alias="organizationId")
    agent_name: StrictStr = Field(description="The agent display name", alias="agentName")
    agent_profile_name: Optional[StrictStr] = Field(default=None, description="The name of the agent profile used for this execution (if any)", alias="agentProfileName")
    agent_profile_id: Optional[StrictStr] = Field(default=None, description="The ID of the agent profile used for this execution (if any)", alias="agentProfileId")
    inputs: Optional[Dict[str, Any]] = Field(default=None, description="Input variables used for this execution")
    execution_result: Optional[AgentsExecutionExecutionResult] = Field(default=None, description="Execution result with outcome, reasoning, and result data", alias="executionResult")
    duration: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Execution duration in seconds (only present for terminal executions)")
    human_labels: List[AgentsExecutionHumanLabel] = Field(description="Human-applied labels for this execution", alias="humanLabels")
    comments: List[AgentsExecutionComment] = Field(description="Comments on this execution")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Optional metadata key-value pairs attached to this execution")
    browser_recording_url: Optional[StrictStr] = Field(default=None, description="Browser recording URL (if a browser session was used and execution is terminal)", alias="browserRecordingUrl")
    browser_live_view_url: Optional[StrictStr] = Field(default=None, description="Browser live view URL for debugging (if a browser session is active and execution is running)", alias="browserLiveViewUrl")
    trigger_context: Optional[AgentsExecutionTriggerContext] = Field(default=None, description="Context about how and by whom this execution was triggered (discriminated by source)", alias="triggerContext")
    __properties: ClassVar[List[str]] = ["id", "agentId", "workflowId", "status", "createdAt", "terminalAt", "organizationId", "agentName", "agentProfileName", "agentProfileId", "inputs", "executionResult", "duration", "humanLabels", "comments", "metadata", "browserRecordingUrl", "browserLiveViewUrl", "triggerContext"]

    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 AgentsExecutionListItem 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 execution_result
        if self.execution_result:
            _dict['executionResult'] = self.execution_result.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in human_labels (list)
        _items = []
        if self.human_labels:
            for _item_human_labels in self.human_labels:
                if _item_human_labels:
                    _items.append(_item_human_labels.to_dict())
            _dict['humanLabels'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in comments (list)
        _items = []
        if self.comments:
            for _item_comments in self.comments:
                if _item_comments:
                    _items.append(_item_comments.to_dict())
            _dict['comments'] = _items
        # override the default output from pydantic by calling `to_dict()` of trigger_context
        if self.trigger_context:
            _dict['triggerContext'] = self.trigger_context.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AgentsExecutionListItem 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"),
            "agentId": obj.get("agentId"),
            "workflowId": obj.get("workflowId"),
            "status": obj.get("status"),
            "createdAt": obj.get("createdAt"),
            "terminalAt": obj.get("terminalAt"),
            "organizationId": obj.get("organizationId"),
            "agentName": obj.get("agentName"),
            "agentProfileName": obj.get("agentProfileName"),
            "agentProfileId": obj.get("agentProfileId"),
            "inputs": obj.get("inputs"),
            "executionResult": AgentsExecutionExecutionResult.from_dict(obj["executionResult"]) if obj.get("executionResult") is not None else None,
            "duration": obj.get("duration"),
            "humanLabels": [AgentsExecutionHumanLabel.from_dict(_item) for _item in obj["humanLabels"]] if obj.get("humanLabels") is not None else None,
            "comments": [AgentsExecutionComment.from_dict(_item) for _item in obj["comments"]] if obj.get("comments") is not None else None,
            "metadata": obj.get("metadata"),
            "browserRecordingUrl": obj.get("browserRecordingUrl"),
            "browserLiveViewUrl": obj.get("browserLiveViewUrl"),
            "triggerContext": AgentsExecutionTriggerContext.from_dict(obj["triggerContext"]) if obj.get("triggerContext") is not None else None
        })
        return _obj


