# coding: utf-8

"""
    BeeL Public API

    Public invoicing API for self-employed professionals in Spain with full VeriFactu support.  **Authentication:** This API uses **API Keys** for authentication. Endpoints are designed for external integrations, automation, and programmatic access.  For browser-based authentication, use the Private API (with Session Cookies).  **Key Features:** - VeriFactu regulatory compliance - Complete invoice management (standard, corrective, simplified) - Customer management - Tax and invoice series configuration - PDF generation - Email sending - Duplicate prevention (idempotency)  **Idempotency:** Creation endpoints (POST) support the `Idempotency-Key` header to prevent duplicates in case of retries.  **Identifiers:** - All resources use UUIDs for technical identification - Invoice numbers are human-readable and searchable 

    The version of the OpenAPI document: 1.0.0
    Contact: it@beel.es
    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 typing import Optional, Set
from typing_extensions import Self

class WebhookDeliveryLog(BaseModel):
    """
    WebhookDeliveryLog
    """ # noqa: E501
    id: Optional[StrictStr] = None
    subscription_id: Optional[StrictStr] = None
    webhook_event_id: Optional[StrictStr] = Field(default=None, description="Groups all delivery attempts for the same logical event.")
    event_type: Optional[StrictStr] = None
    attempt_number: Optional[StrictInt] = Field(default=None, description="Delivery attempt number (1 = first, 2 = first retry, etc.)")
    http_status: Optional[StrictInt] = Field(default=None, description="HTTP response status code. Null if connection failed.")
    response_body: Optional[StrictStr] = None
    duration_ms: Optional[StrictInt] = Field(default=None, description="Delivery duration in milliseconds.")
    success: Optional[StrictBool] = None
    error_message: Optional[StrictStr] = Field(default=None, description="Error description for failed deliveries (timeout, connection error, etc.)")
    payload: Optional[StrictStr] = Field(default=None, description="The JSON payload that was sent (or attempted) to your endpoint.")
    request_headers: Optional[Dict[str, StrictStr]] = Field(default=None, description="HTTP headers sent to your endpoint with this delivery attempt. Includes `BeeL-Signature`, `BeeL-Event`, `BeeL-Delivery`, and `Idempotency-Key`. ")
    delivered_at: Optional[datetime] = None
    __properties: ClassVar[List[str]] = ["id", "subscription_id", "webhook_event_id", "event_type", "attempt_number", "http_status", "response_body", "duration_ms", "success", "error_message", "payload", "request_headers", "delivered_at"]

    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 WebhookDeliveryLog 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 http_status (nullable) is None
        # and model_fields_set contains the field
        if self.http_status is None and "http_status" in self.model_fields_set:
            _dict['http_status'] = 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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of WebhookDeliveryLog 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"),
            "subscription_id": obj.get("subscription_id"),
            "webhook_event_id": obj.get("webhook_event_id"),
            "event_type": obj.get("event_type"),
            "attempt_number": obj.get("attempt_number"),
            "http_status": obj.get("http_status"),
            "response_body": obj.get("response_body"),
            "duration_ms": obj.get("duration_ms"),
            "success": obj.get("success"),
            "error_message": obj.get("error_message"),
            "payload": obj.get("payload"),
            "request_headers": obj.get("request_headers"),
            "delivered_at": obj.get("delivered_at")
        })
        return _obj


