# 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
from typing import Any, ClassVar, Dict, List, Optional
from pinterestsdk.models.ad_group_update_request import AdGroupUpdateRequest
from pinterestsdk.models.ad_update_request import AdUpdateRequest
from pinterestsdk.models.campaign_update_request import CampaignUpdateRequest
from pinterestsdk.models.catalogs_product_groups_update_request import CatalogsProductGroupsUpdateRequest
from pinterestsdk.models.keyword_update import KeywordUpdate
from pinterestsdk.models.label_bulk_update_request import LabelBulkUpdateRequest
from pinterestsdk.models.product_group_promotion_update_request import ProductGroupPromotionUpdateRequest
from typing import Optional, Set
from typing_extensions import Self

class BulkUpsertRequestUpdate(BaseModel):
    """
    Request for creation of entities in bulk.
    """ # noqa: E501
    ad_groups: Optional[List[AdGroupUpdateRequest]] = None
    ads: Optional[List[AdUpdateRequest]] = None
    campaigns: Optional[List[CampaignUpdateRequest]] = None
    catalog_product_groups: Optional[List[CatalogsProductGroupsUpdateRequest]] = None
    keywords: Optional[List[KeywordUpdate]] = None
    labels: Optional[List[LabelBulkUpdateRequest]] = None
    product_groups: Optional[List[ProductGroupPromotionUpdateRequest]] = None
    __properties: ClassVar[List[str]] = ["ad_groups", "ads", "campaigns", "catalog_product_groups", "keywords", "labels", "product_groups"]

    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 BulkUpsertRequestUpdate 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 each item in ad_groups (list)
        _items = []
        if self.ad_groups:
            for _item_ad_groups in self.ad_groups:
                if _item_ad_groups:
                    _items.append(_item_ad_groups.to_dict())
            _dict['ad_groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in ads (list)
        _items = []
        if self.ads:
            for _item_ads in self.ads:
                if _item_ads:
                    _items.append(_item_ads.to_dict())
            _dict['ads'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in campaigns (list)
        _items = []
        if self.campaigns:
            for _item_campaigns in self.campaigns:
                if _item_campaigns:
                    _items.append(_item_campaigns.to_dict())
            _dict['campaigns'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in catalog_product_groups (list)
        _items = []
        if self.catalog_product_groups:
            for _item_catalog_product_groups in self.catalog_product_groups:
                if _item_catalog_product_groups:
                    _items.append(_item_catalog_product_groups.to_dict())
            _dict['catalog_product_groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in keywords (list)
        _items = []
        if self.keywords:
            for _item_keywords in self.keywords:
                if _item_keywords:
                    _items.append(_item_keywords.to_dict())
            _dict['keywords'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in labels (list)
        _items = []
        if self.labels:
            for _item_labels in self.labels:
                if _item_labels:
                    _items.append(_item_labels.to_dict())
            _dict['labels'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in product_groups (list)
        _items = []
        if self.product_groups:
            for _item_product_groups in self.product_groups:
                if _item_product_groups:
                    _items.append(_item_product_groups.to_dict())
            _dict['product_groups'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "ad_groups": [AdGroupUpdateRequest.from_dict(_item) for _item in obj["ad_groups"]] if obj.get("ad_groups") is not None else None,
            "ads": [AdUpdateRequest.from_dict(_item) for _item in obj["ads"]] if obj.get("ads") is not None else None,
            "campaigns": [CampaignUpdateRequest.from_dict(_item) for _item in obj["campaigns"]] if obj.get("campaigns") is not None else None,
            "catalog_product_groups": [CatalogsProductGroupsUpdateRequest.from_dict(_item) for _item in obj["catalog_product_groups"]] if obj.get("catalog_product_groups") is not None else None,
            "keywords": [KeywordUpdate.from_dict(_item) for _item in obj["keywords"]] if obj.get("keywords") is not None else None,
            "labels": [LabelBulkUpdateRequest.from_dict(_item) for _item in obj["labels"]] if obj.get("labels") is not None else None,
            "product_groups": [ProductGroupPromotionUpdateRequest.from_dict(_item) for _item in obj["product_groups"]] if obj.get("product_groups") is not None else None
        })
        return _obj


