# 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.5
    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, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from financial_reports_generated_client.models.status_enum import StatusEnum
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class WebhookDeliveryDetail(BaseModel):
    """
    WebhookDeliveryDetail
    """ # noqa: E501
    uuid: UUID
    webhook_id: StrictInt
    event_type: StrictStr
    filing_id: Optional[StrictInt] = Field(description="ID of the filing reference to reconstruct payload")
    status: StatusEnum
    response_status_code: Optional[StrictInt]
    duration_ms: Optional[StrictInt]
    response_body: Optional[StrictStr]
    created_at: datetime
    request_headers: Dict[str, Any] = Field(description="Reconstructed request headers that were sent with this delivery.")
    request_payload: Dict[str, Any] = Field(description="Reconstructed request payload. Built dynamically from the referenced filing.")
    __properties: ClassVar[List[str]] = ["uuid", "webhook_id", "event_type", "filing_id", "status", "response_status_code", "duration_ms", "response_body", "created_at", "request_headers", "request_payload"]

    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 WebhookDeliveryDetail 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "uuid",
            "webhook_id",
            "event_type",
            "filing_id",
            "status",
            "response_status_code",
            "duration_ms",
            "response_body",
            "created_at",
            "request_headers",
            "request_payload",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if filing_id (nullable) is None
        # and model_fields_set contains the field
        if self.filing_id is None and "filing_id" in self.model_fields_set:
            _dict['filing_id'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "uuid": obj.get("uuid"),
            "webhook_id": obj.get("webhook_id"),
            "event_type": obj.get("event_type"),
            "filing_id": obj.get("filing_id"),
            "status": obj.get("status"),
            "response_status_code": obj.get("response_status_code"),
            "duration_ms": obj.get("duration_ms"),
            "response_body": obj.get("response_body"),
            "created_at": obj.get("created_at"),
            "request_headers": obj.get("request_headers"),
            "request_payload": obj.get("request_payload")
        })
        return _obj


