# 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.business_access_user_summary import BusinessAccessUserSummary
from typing import Optional, Set
from typing_extensions import Self

class AssetGroupBinding(BaseModel):
    """
    AssetGroupBinding
    """ # noqa: E501
    ad_accounts_ids: Optional[List[Annotated[str, Field(strict=True)]]] = Field(default=None, description="A list of ad account IDs under the asset group")
    asset_group_description: Optional[StrictStr] = Field(default=None, description="Asset group description")
    asset_group_name: Optional[StrictStr] = Field(default=None, description="Asset Group name")
    asset_group_types: Optional[List[StrictStr]] = Field(default=None, description="Asset group types")
    catalogs_ids: Optional[List[Annotated[str, Field(strict=True)]]] = Field(default=None, description="A list of catalog IDs under asset group")
    created_by: Optional[BusinessAccessUserSummary] = Field(default=None, description="The data of the user that created the asset group.")
    created_time: Optional[StrictInt] = Field(default=None, description="The creation time of the asset group")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Asset Group ID.")
    owner: Optional[BusinessAccessUserSummary] = Field(default=None, description="The data of the business that owns the asset group.")
    profiles_ids: Optional[List[Annotated[str, Field(strict=True)]]] = Field(default=None, description="A list of profile IDs under asset group")
    updated_time: Optional[StrictInt] = Field(default=None, description="The last update time of the asset group")
    __properties: ClassVar[List[str]] = ["ad_accounts_ids", "asset_group_description", "asset_group_name", "asset_group_types", "catalogs_ids", "created_by", "created_time", "id", "owner", "profiles_ids", "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 AssetGroupBinding 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 created_by
        if self.created_by:
            _dict['created_by'] = self.created_by.to_dict()
        # 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 ad_accounts_ids (nullable) is None
        # and model_fields_set contains the field
        if self.ad_accounts_ids is None and "ad_accounts_ids" in self.model_fields_set:
            _dict['ad_accounts_ids'] = None

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

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

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

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

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

        # set to None if profiles_ids (nullable) is None
        # and model_fields_set contains the field
        if self.profiles_ids is None and "profiles_ids" in self.model_fields_set:
            _dict['profiles_ids'] = 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 AssetGroupBinding from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "ad_accounts_ids": obj.get("ad_accounts_ids"),
            "asset_group_description": obj.get("asset_group_description"),
            "asset_group_name": obj.get("asset_group_name"),
            "asset_group_types": obj.get("asset_group_types"),
            "catalogs_ids": obj.get("catalogs_ids"),
            "created_by": BusinessAccessUserSummary.from_dict(obj["created_by"]) if obj.get("created_by") is not None else None,
            "created_time": obj.get("created_time"),
            "id": obj.get("id"),
            "owner": BusinessAccessUserSummary.from_dict(obj["owner"]) if obj.get("owner") is not None else None,
            "profiles_ids": obj.get("profiles_ids"),
            "updated_time": obj.get("updated_time")
        })
        return _obj


