# coding: utf-8

"""
    Hindsight HTTP API

    HTTP API for Hindsight

    The version of the OpenAPI document: 0.5.3
    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 pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class WebhookDeliveryResponse(BaseModel):
    """
    Response model for a webhook delivery record.
    """ # noqa: E501
    id: StrictStr
    webhook_id: Optional[StrictStr]
    url: StrictStr
    event_type: StrictStr
    status: StrictStr
    attempts: StrictInt
    next_retry_at: Optional[StrictStr] = None
    last_error: Optional[StrictStr] = None
    last_response_status: Optional[StrictInt] = None
    last_response_body: Optional[StrictStr] = None
    last_attempt_at: Optional[StrictStr] = None
    created_at: Optional[StrictStr] = None
    updated_at: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["id", "webhook_id", "url", "event_type", "status", "attempts", "next_retry_at", "last_error", "last_response_status", "last_response_body", "last_attempt_at", "created_at", "updated_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 WebhookDeliveryResponse 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 webhook_id (nullable) is None
        # and model_fields_set contains the field
        if self.webhook_id is None and "webhook_id" in self.model_fields_set:
            _dict['webhook_id'] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of WebhookDeliveryResponse 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"),
            "webhook_id": obj.get("webhook_id"),
            "url": obj.get("url"),
            "event_type": obj.get("event_type"),
            "status": obj.get("status"),
            "attempts": obj.get("attempts"),
            "next_retry_at": obj.get("next_retry_at"),
            "last_error": obj.get("last_error"),
            "last_response_status": obj.get("last_response_status"),
            "last_response_body": obj.get("last_response_body"),
            "last_attempt_at": obj.get("last_attempt_at"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


