# coding: utf-8

"""
    Voucherify API

    Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details.

    The version of the OpenAPI document: v2018-08-01
    Contact: support@voucherify.io
    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 voucherify.models.junction import Junction
from voucherify.models.parameter_filters_list_publications_campaign_name import ParameterFiltersListPublicationsCampaignName
from voucherify.models.parameter_filters_list_publications_customer_id import ParameterFiltersListPublicationsCustomerId
from voucherify.models.parameter_filters_list_publications_failure_code import ParameterFiltersListPublicationsFailureCode
from voucherify.models.parameter_filters_list_publications_is_referral_code import ParameterFiltersListPublicationsIsReferralCode
from voucherify.models.parameter_filters_list_publications_parent_object_id import ParameterFiltersListPublicationsParentObjectId
from voucherify.models.parameter_filters_list_publications_related_object_id import ParameterFiltersListPublicationsRelatedObjectId
from voucherify.models.parameter_filters_list_publications_result import ParameterFiltersListPublicationsResult
from voucherify.models.parameter_filters_list_publications_source_id import ParameterFiltersListPublicationsSourceId
from voucherify.models.parameter_filters_list_publications_voucher_type import ParameterFiltersListPublicationsVoucherType
from typing import Optional, Set
from typing_extensions import Self

class ParameterFiltersListPublications(BaseModel):
    """
    ParameterFiltersListPublications
    """ # noqa: E501
    junction: Optional[Junction] = None
    failure_code: Optional[ParameterFiltersListPublicationsFailureCode] = None
    result: Optional[ParameterFiltersListPublicationsResult] = None
    customer_id: Optional[ParameterFiltersListPublicationsCustomerId] = None
    campaign_name: Optional[ParameterFiltersListPublicationsCampaignName] = None
    voucher_type: Optional[ParameterFiltersListPublicationsVoucherType] = None
    is_referral_code: Optional[ParameterFiltersListPublicationsIsReferralCode] = None
    parent_object_id: Optional[ParameterFiltersListPublicationsParentObjectId] = None
    related_object_id: Optional[ParameterFiltersListPublicationsRelatedObjectId] = None
    source_id: Optional[ParameterFiltersListPublicationsSourceId] = None
    __properties: ClassVar[List[str]] = ["junction", "failure_code", "result", "customer_id", "campaign_name", "voucher_type", "is_referral_code", "parent_object_id", "related_object_id", "source_id"]

    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 ParameterFiltersListPublications 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 failure_code
        if self.failure_code:
            _dict['failure_code'] = self.failure_code.to_dict()
        # override the default output from pydantic by calling `to_dict()` of result
        if self.result:
            _dict['result'] = self.result.to_dict()
        # override the default output from pydantic by calling `to_dict()` of customer_id
        if self.customer_id:
            _dict['customer_id'] = self.customer_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of campaign_name
        if self.campaign_name:
            _dict['campaign_name'] = self.campaign_name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of voucher_type
        if self.voucher_type:
            _dict['voucher_type'] = self.voucher_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of is_referral_code
        if self.is_referral_code:
            _dict['is_referral_code'] = self.is_referral_code.to_dict()
        # override the default output from pydantic by calling `to_dict()` of parent_object_id
        if self.parent_object_id:
            _dict['parent_object_id'] = self.parent_object_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of related_object_id
        if self.related_object_id:
            _dict['related_object_id'] = self.related_object_id.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source_id
        if self.source_id:
            _dict['source_id'] = self.source_id.to_dict()
        # set to None if failure_code (nullable) is None
        # and model_fields_set contains the field
        if self.failure_code is None and "failure_code" in self.model_fields_set:
            _dict['failure_code'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "junction": obj.get("junction"),
            "failure_code": ParameterFiltersListPublicationsFailureCode.from_dict(obj["failure_code"]) if obj.get("failure_code") is not None else None,
            "result": ParameterFiltersListPublicationsResult.from_dict(obj["result"]) if obj.get("result") is not None else None,
            "customer_id": ParameterFiltersListPublicationsCustomerId.from_dict(obj["customer_id"]) if obj.get("customer_id") is not None else None,
            "campaign_name": ParameterFiltersListPublicationsCampaignName.from_dict(obj["campaign_name"]) if obj.get("campaign_name") is not None else None,
            "voucher_type": ParameterFiltersListPublicationsVoucherType.from_dict(obj["voucher_type"]) if obj.get("voucher_type") is not None else None,
            "is_referral_code": ParameterFiltersListPublicationsIsReferralCode.from_dict(obj["is_referral_code"]) if obj.get("is_referral_code") is not None else None,
            "parent_object_id": ParameterFiltersListPublicationsParentObjectId.from_dict(obj["parent_object_id"]) if obj.get("parent_object_id") is not None else None,
            "related_object_id": ParameterFiltersListPublicationsRelatedObjectId.from_dict(obj["related_object_id"]) if obj.get("related_object_id") is not None else None,
            "source_id": ParameterFiltersListPublicationsSourceId.from_dict(obj["source_id"]) if obj.get("source_id") is not None else None
        })
        return _obj


