# 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 pinterestsdk.models.audience_rule import AudienceRule
from typing import Optional, Set
from typing_extensions import Self

class Audience(BaseModel):
    """
    Audience
    """ # noqa: E501
    ad_account_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Ad account ID.")
    audience_type: Optional[StrictStr] = Field(default=None, description="<a href=\"/docs/reference/glossary/#Audience Types\">Audience types</a>: ACTALIKE, ENGAGEMENT, CUSTOMER_LIST and VISITOR")
    created_by_company_name: Optional[StrictStr] = Field(default=None, description="The company that created this audience.")
    created_timestamp: Optional[StrictInt] = Field(default=None, description="Creation time. Unix timestamp in seconds.")
    description: Optional[StrictStr] = Field(default=None, description="Audience description.")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Audience ID.")
    name: Optional[StrictStr] = Field(default=None, description="Audience name.")
    rule: Optional[AudienceRule] = None
    size: Optional[StrictInt] = Field(default=None, description="Audience size.")
    status: Optional[StrictStr] = Field(default=None, description="Audience status. READY, INITIALIZING, TOO_SMALL - Each audience list needs to have at least 100 people with Pinterest accounts before you can start using it.")
    type: Optional[StrictStr] = Field(default=None, description="Always \"audience\".")
    updated_timestamp: Optional[StrictInt] = Field(default=None, description="Last update time. Unix timestamp in seconds.")
    __properties: ClassVar[List[str]] = ["ad_account_id", "audience_type", "created_by_company_name", "created_timestamp", "description", "id", "name", "rule", "size", "status", "type", "updated_timestamp"]

    @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

    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 Audience 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 rule
        if self.rule:
            _dict['rule'] = self.rule.to_dict()
        # set to None if created_by_company_name (nullable) is None
        # and model_fields_set contains the field
        if self.created_by_company_name is None and "created_by_company_name" in self.model_fields_set:
            _dict['created_by_company_name'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ad_account_id": obj.get("ad_account_id"),
            "audience_type": obj.get("audience_type"),
            "created_by_company_name": obj.get("created_by_company_name"),
            "created_timestamp": obj.get("created_timestamp"),
            "description": obj.get("description"),
            "id": obj.get("id"),
            "name": obj.get("name"),
            "rule": AudienceRule.from_dict(obj["rule"]) if obj.get("rule") is not None else None,
            "size": obj.get("size"),
            "status": obj.get("status"),
            "type": obj.get("type"),
            "updated_timestamp": obj.get("updated_timestamp")
        })
        return _obj


