# coding: utf-8

"""
    Coinbase Developer Platform APIs

    The Coinbase Developer Platform APIs - leading the world's transition onchain.

    The version of the OpenAPI document: 2.0.0
    Contact: cdp@coinbase.com
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from cdp.openapi_client.models.webhook_subscription_response_metadata import WebhookSubscriptionResponseMetadata
from cdp.openapi_client.models.webhook_target import WebhookTarget
from typing import Optional, Set
from typing_extensions import Self

class WebhookSubscriptionResponse(BaseModel):
    """
    Response containing webhook subscription details.
    """ # noqa: E501
    created_at: datetime = Field(description="When the subscription was created.", alias="createdAt")
    description: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=500)]] = Field(default=None, description="Description of the webhook subscription.")
    event_types: List[StrictStr] = Field(description="Types of events to subscribe to. Event types follow a three-part dot-separated format: service.resource.verb (e.g., \"onchain.activity.detected\", \"wallet.activity.detected\", \"onramp.transaction.created\"). ", alias="eventTypes")
    is_enabled: StrictBool = Field(description="Whether the subscription is enabled.", alias="isEnabled")
    metadata: Optional[WebhookSubscriptionResponseMetadata] = None
    secret: StrictStr = Field(description="Secret for webhook signature validation.")
    subscription_id: StrictStr = Field(description="Unique identifier for the subscription.", alias="subscriptionId")
    target: WebhookTarget
    label_key: Optional[StrictStr] = Field(default=None, description="(Deprecated) Use `labels` field instead.  Label key for filtering events. Present when subscription uses traditional single-label format. Maintained for backward compatibility only. ", alias="labelKey")
    label_value: Optional[StrictStr] = Field(default=None, description="(Deprecated) Use `labels` field instead.  Label value for filtering events. Present when subscription uses traditional single-label format. Maintained for backward compatibility only. ", alias="labelValue")
    labels: Optional[Dict[str, StrictStr]] = Field(default=None, description="Multi-label filters using total overlap logic. Total overlap means the subscription only triggers when events contain ALL these key-value pairs. Present when subscription uses multi-label format. ")
    __properties: ClassVar[List[str]] = ["createdAt", "description", "eventTypes", "isEnabled", "metadata", "secret", "subscriptionId", "target", "labelKey", "labelValue", "labels"]

    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 WebhookSubscriptionResponse 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 metadata
        if self.metadata:
            _dict['metadata'] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of target
        if self.target:
            _dict['target'] = self.target.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "createdAt": obj.get("createdAt"),
            "description": obj.get("description"),
            "eventTypes": obj.get("eventTypes"),
            "isEnabled": obj.get("isEnabled"),
            "metadata": WebhookSubscriptionResponseMetadata.from_dict(obj["metadata"]) if obj.get("metadata") is not None else None,
            "secret": obj.get("secret"),
            "subscriptionId": obj.get("subscriptionId"),
            "target": WebhookTarget.from_dict(obj["target"]) if obj.get("target") is not None else None,
            "labelKey": obj.get("labelKey"),
            "labelValue": obj.get("labelValue"),
            "labels": obj.get("labels")
        })
        return _obj


