# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.ad_account_owner import AdAccountOwner
from pinterestsdk.models.business_access_role import BusinessAccessRole
from pinterestsdk.models.country import Country
from pinterestsdk.models.currency import Currency
from typing import Optional, Set
from typing_extensions import Self

class AdAccount(BaseModel):
    """
    AdAccount
    """ # noqa: E501
    country: Optional[Country] = None
    created_time: Optional[StrictInt] = Field(default=None, description=" Creation time. Unix timestamp in seconds.")
    currency: Optional[Currency] = None
    id: Annotated[str, Field(strict=True, max_length=18)]
    name: Optional[Annotated[str, Field(strict=True, max_length=256)]] = Field(default=None, description="Ad account name.")
    owner: Optional[AdAccountOwner] = Field(default=None, description="Ad account owner")
    permissions: Optional[List[BusinessAccessRole]] = None
    updated_time: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["country", "created_time", "currency", "id", "name", "owner", "permissions", "updated_time"]

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        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 AdAccount 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "created_time",
            "owner",
            "permissions",
            "updated_time",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of owner
        if self.owner:
            _dict['owner'] = self.owner.to_dict()
        # set to None if created_time (nullable) is None
        # and model_fields_set contains the field
        if self.created_time is None and "created_time" in self.model_fields_set:
            _dict['created_time'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "country": obj.get("country"),
            "created_time": obj.get("created_time"),
            "currency": obj.get("currency"),
            "id": obj.get("id"),
            "name": obj.get("name"),
            "owner": AdAccountOwner.from_dict(obj["owner"]) if obj.get("owner") is not None else None,
            "permissions": obj.get("permissions"),
            "updated_time": obj.get("updated_time")
        })
        return _obj


