# coding: utf-8

"""
    FinancialReports API

     Welcome to the FinancialReports API.  ### Access Levels This API is tiered based on data granularity.  | Level | Name | Description | | :--- | :--- | :--- | | **Level 1** | **Standard Access** | Access to raw PDF/XBRL metadata, company profiles, ISIC classifications, reference data, and **point-in-time audit trails**. | | **Level 2** | **Processed Filings** | Access to converted content (Markdown/JSON) and full-text search capabilities. | | **Level 3** | **RAG / Agent** | Access to specific extracted financial line items (Revenue, EBITDA, etc.) mapped to standard taxonomies, and access to the conversational RAG agent. |  ### Rate Limiting To ensure stability, this API uses a dual-layer rate limit: 1.  **Burst Limit:** A short-term speed limit (e.g., 5 requests/second) to prevent system overload. 2.  **Quota Limit:** A monthly allowance of total requests based on your subscription plan.  Check the response headers `X-RateLimit-Burst-Limit` and `X-RateLimit-Monthly-Remaining` for your current status.  ### Authentication All API requests must be authenticated via the **X-API-Key** header. 

    The version of the OpenAPI document: 1.1.2
    Contact: api@financialreports.eu
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class ChatMessageItem(BaseModel):
    """
    ChatMessageItem
    """ # noqa: E501
    id: StrictInt
    role: StrictStr
    content: StrictStr
    thought_signature: Optional[StrictStr]
    tool_calls: Optional[Any]
    tool_results: Optional[Any]
    created_at: datetime
    __properties: ClassVar[List[str]] = ["id", "role", "content", "thought_signature", "tool_calls", "tool_results", "created_at"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ChatMessageItem 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 tool_calls
        if self.tool_calls:
            _dict['tool_calls'] = self.tool_calls.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tool_results
        if self.tool_results:
            _dict['tool_results'] = self.tool_results.to_dict()
        # set to None if thought_signature (nullable) is None
        # and model_fields_set contains the field
        if self.thought_signature is None and "thought_signature" in self.model_fields_set:
            _dict['thought_signature'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ChatMessageItem 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"),
            "role": obj.get("role"),
            "content": obj.get("content"),
            "thought_signature": obj.get("thought_signature"),
            "tool_calls": OneOf.from_dict(obj["tool_calls"]) if obj.get("tool_calls") is not None else None,
            "tool_results": OneOf.from_dict(obj["tool_results"]) if obj.get("tool_results") is not None else None,
            "created_at": obj.get("created_at")
        })
        return _obj


