# 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.product_condition import ProductCondition
from openapi_client.models.campaign.product_partition_type import ProductPartitionType
from typing_extensions import Self

class ProductPartition(BaseModel):
    """
    ProductPartition
    """ # noqa: E501
    parent_criterion_id: Optional[StrictStr] = Field(default=None, alias="ParentCriterionId")
    condition: Optional[ProductCondition] = Field(default=None, alias="Condition")
    partition_type: Optional[ProductPartitionType] = Field(default=None, alias="PartitionType")
    type: Optional[StrictStr] = Field(default='ProductPartition', alias="Type")
    __properties: ClassVar[List[str]] = ["ParentCriterionId", "Condition", "PartitionType", "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 ProductPartition 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 condition
        if self.condition:
            _dict['Condition'] = self.condition.to_dict()
        # set to None if parent_criterion_id (nullable) is None
        # and model_fields_set contains the field
        if self.parent_criterion_id is None and "parent_criterion_id" in self.model_fields_set:
            _dict['ParentCriterionId'] = None

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

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

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

        _obj = cls.model_validate({
            "ParentCriterionId": obj.get("ParentCriterionId") if obj.get("ParentCriterionId") is not None else None,
                        "Condition": ProductCondition.from_dict(obj["Condition"]) if obj.get("Condition") is not None else None,
                        "PartitionType": obj.get("PartitionType") if obj.get("PartitionType") is not None else None,
                        "Type": obj.get("Type") if obj.get("Type") is not None else 'ProductPartition'
        })
        return _obj
