# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.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 pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class AdAccountGetSubscriptionResponse(BaseModel):
    """
    AdAccountGetSubscriptionResponse
    """ # noqa: E501
    lead_form_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Lead form ID.")
    webhook_url: Optional[StrictStr] = Field(default=None, description="Standard HTTPS webhook URL.")
    ad_account_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The Ad Account ID that this lead form belongs to.")
    api_version: Optional[StrictStr] = Field(default=None, description="API version.")
    created_time: Optional[StrictInt] = Field(default=None, description="Lead subscription creation time. Unix timestamp in milliseconds.")
    cryptographic_algorithm: Optional[StrictStr] = Field(default=None, description="Lead data encryption algorithm.")
    cryptographic_key: Optional[StrictStr] = Field(default=None, description="Base64 encoded key for client to decrypt lead data.")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Subscription ID.")
    user_account_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="User account used to subscribe lead data.")
    __properties: ClassVar[List[str]] = ["lead_form_id", "webhook_url", "ad_account_id", "api_version", "created_time", "cryptographic_algorithm", "cryptographic_key", "id", "user_account_id"]

    @field_validator('lead_form_id')
    def lead_form_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

    @field_validator('ad_account_id')
    def ad_account_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

    @field_validator('user_account_id')
    def user_account_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "lead_form_id": obj.get("lead_form_id"),
            "webhook_url": obj.get("webhook_url"),
            "ad_account_id": obj.get("ad_account_id"),
            "api_version": obj.get("api_version"),
            "created_time": obj.get("created_time"),
            "cryptographic_algorithm": obj.get("cryptographic_algorithm"),
            "cryptographic_key": obj.get("cryptographic_key"),
            "id": obj.get("id"),
            "user_account_id": obj.get("user_account_id")
        })
        return _obj


