# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from pinterestsdk.models.advanced_auction_bid_options import AdvancedAuctionBidOptions
from pinterestsdk.models.advanced_auction_operation_error import AdvancedAuctionOperationError
from pinterestsdk.models.country import Country
from pinterestsdk.models.language import Language
from pinterestsdk.models.update_mask_bid_option_field import UpdateMaskBidOptionField
from typing import Optional, Set
from typing_extensions import Self

class AdvancedAuctionItemsSubmitUpsertRecord(BaseModel):
    """
    Object describing an item bid option upsert operation
    """ # noqa: E501
    country: Country
    item_id: StrictStr = Field(description="The catalog retail item id in the merchant namespace")
    language: Language
    bid_options: AdvancedAuctionBidOptions
    errors: Optional[List[AdvancedAuctionOperationError]] = Field(default=None, description="Array with validation errors for the supplied item bid option modification operation. A non empty errors list means this single item operation was not applied.")
    update_mask: Optional[List[UpdateMaskBidOptionField]] = Field(description="The list of item bid option fields to be set or updated. Fields specified in the updated mask without a value specified in the `bid_options` object in the body will be set to `null`. If an item bid option record is being created, fields not specified in the update mask will be initialized to `null`.")
    __properties: ClassVar[List[str]] = ["country", "item_id", "language", "bid_options", "errors", "update_mask"]

    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 AdvancedAuctionItemsSubmitUpsertRecord 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 bid_options
        if self.bid_options:
            _dict['bid_options'] = self.bid_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in errors (list)
        _items = []
        if self.errors:
            for _item_errors in self.errors:
                if _item_errors:
                    _items.append(_item_errors.to_dict())
            _dict['errors'] = _items
        # set to None if update_mask (nullable) is None
        # and model_fields_set contains the field
        if self.update_mask is None and "update_mask" in self.model_fields_set:
            _dict['update_mask'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AdvancedAuctionItemsSubmitUpsertRecord 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"),
            "item_id": obj.get("item_id"),
            "language": obj.get("language"),
            "bid_options": AdvancedAuctionBidOptions.from_dict(obj["bid_options"]) if obj.get("bid_options") is not None else None,
            "errors": [AdvancedAuctionOperationError.from_dict(_item) for _item in obj["errors"]] if obj.get("errors") is not None else None,
            "update_mask": obj.get("update_mask")
        })
        return _obj


