# 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 IntegrationRecord(BaseModel):
    """
    Integration record
    """ # noqa: E501
    additional_id_1: Optional[StrictStr] = None
    connected_advertiser_id: Optional[StrictStr] = None
    connected_lba_id: Optional[StrictStr] = None
    connected_merchant_id: Optional[StrictStr] = None
    connected_tag_id: Optional[StrictStr] = None
    connected_user_id: Optional[StrictStr] = None
    created_time: Optional[StrictInt] = None
    external_business_id: Optional[StrictStr] = None
    id: Optional[Annotated[str, Field(strict=True)]] = None
    partner_access_token: Optional[StrictStr] = None
    partner_access_token_expiry: Optional[StrictInt] = None
    partner_metadata: Optional[StrictStr] = None
    partner_primary_email: Optional[StrictStr] = None
    partner_refresh_token: Optional[StrictStr] = None
    partner_refresh_token_expiry: Optional[StrictInt] = None
    scopes: Optional[StrictStr] = None
    updated_time: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["additional_id_1", "connected_advertiser_id", "connected_lba_id", "connected_merchant_id", "connected_tag_id", "connected_user_id", "created_time", "external_business_id", "id", "partner_access_token", "partner_access_token_expiry", "partner_metadata", "partner_primary_email", "partner_refresh_token", "partner_refresh_token_expiry", "scopes", "updated_time"]

    @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

    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 IntegrationRecord 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.
        """
        excluded_fields: Set[str] = set([
            "connected_advertiser_id",
            "connected_user_id",
        ])

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "additional_id_1": obj.get("additional_id_1"),
            "connected_advertiser_id": obj.get("connected_advertiser_id"),
            "connected_lba_id": obj.get("connected_lba_id"),
            "connected_merchant_id": obj.get("connected_merchant_id"),
            "connected_tag_id": obj.get("connected_tag_id"),
            "connected_user_id": obj.get("connected_user_id"),
            "created_time": obj.get("created_time"),
            "external_business_id": obj.get("external_business_id"),
            "id": obj.get("id"),
            "partner_access_token": obj.get("partner_access_token"),
            "partner_access_token_expiry": obj.get("partner_access_token_expiry"),
            "partner_metadata": obj.get("partner_metadata"),
            "partner_primary_email": obj.get("partner_primary_email"),
            "partner_refresh_token": obj.get("partner_refresh_token"),
            "partner_refresh_token_expiry": obj.get("partner_refresh_token_expiry"),
            "scopes": obj.get("scopes"),
            "updated_time": obj.get("updated_time")
        })
        return _obj


