# coding: utf-8

"""
    CampaignManagementService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union, Set
from openapi_client.models.campaign.campaign_criterion_status import CampaignCriterionStatus
from openapi_client.models.campaign.criterion import Criterion
from openapi_client.models.campaign.criterion_bid import CriterionBid
from openapi_client.models.campaign.criterion_cashback import CriterionCashback
from openapi_client.models.campaign.key_value_pair_ofstring_andstring import KeyValuePairOfstringAndstring
from typing_extensions import Self

class BiddableCampaignCriterion(BaseModel):
    """
    BiddableCampaignCriterion
    """ # noqa: E501
    criterion_bid: Optional[CriterionBid] = Field(default=None, alias="CriterionBid")
    criterion_cashback: Optional[CriterionCashback] = Field(default=None, alias="CriterionCashback")
    id: Optional[StrictStr] = Field(default=None, alias="Id")
    campaign_id: Optional[StrictStr] = Field(default=None, alias="CampaignId")
    criterion: Optional[Criterion] = Field(default=None, alias="Criterion")
    forward_compatibility_map: Optional[List[Optional[KeyValuePairOfstringAndstring]]] = Field(default=None, alias="ForwardCompatibilityMap")
    status: Optional[CampaignCriterionStatus] = Field(default=None, alias="Status")
    type: Optional[StrictStr] = Field(default='BiddableCampaignCriterion', alias="Type")
    __properties: ClassVar[List[str]] = ["CriterionBid", "CriterionCashback", "Id", "CampaignId", "Criterion", "ForwardCompatibilityMap", "Status", "Type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )
	
    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 BiddableCampaignCriterion 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 criterion_bid
        if self.criterion_bid:
            _dict['CriterionBid'] = self.criterion_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of criterion_cashback
        if self.criterion_cashback:
            _dict['CriterionCashback'] = self.criterion_cashback.to_dict()
        # override the default output from pydantic by calling `to_dict()` of criterion
        if self.criterion:
            _dict['Criterion'] = self.criterion.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in forward_compatibility_map (list)
        _items = []
        if self.forward_compatibility_map:
            for _item_forward_compatibility_map in self.forward_compatibility_map:
                if _item_forward_compatibility_map:
                    _items.append(_item_forward_compatibility_map.to_dict())
            _dict['ForwardCompatibilityMap'] = _items
        # set to None if criterion_bid (nullable) is None
        # and model_fields_set contains the field
        if self.criterion_bid is None and "criterion_bid" in self.model_fields_set:
            _dict['CriterionBid'] = None

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "CriterionBid": CriterionBid.from_dict(obj["CriterionBid"]) if obj.get("CriterionBid") is not None else None,
                        "CriterionCashback": CriterionCashback.from_dict(obj["CriterionCashback"]) if obj.get("CriterionCashback") is not None else None,
                        "Id": obj.get("Id") if obj.get("Id") is not None else None,
                        "CampaignId": obj.get("CampaignId") if obj.get("CampaignId") is not None else None,
                        "Criterion": Criterion.from_dict(obj["Criterion"]) if obj.get("Criterion") is not None else None,
                        "ForwardCompatibilityMap": [KeyValuePairOfstringAndstring.from_dict(_item) for _item in obj["ForwardCompatibilityMap"]] if obj.get("ForwardCompatibilityMap") is not None else None,
                        "Status": obj.get("Status") if obj.get("Status") is not None else None,
                        "Type": obj.get("Type") if obj.get("Type") is not None else 'BiddableCampaignCriterion'
        })
        return _obj
