# coding: utf-8

"""
    用户全部 API 文档

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

    The version of the OpenAPI document: v1
    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 ZSGF.Client.models.contribute_detail import ContributeDetail
from typing import Optional, Set
from typing_extensions import Self

class VoucherDetail(BaseModel):
    """
    VoucherDetail
    """ # noqa: E501
    amount: Optional[StrictStr] = None
    id: Optional[StrictStr] = None
    memo: Optional[StrictStr] = None
    merchant_contribute: Optional[StrictStr] = Field(default=None, alias="merchantContribute")
    name: Optional[StrictStr] = None
    other_contribute: Optional[StrictStr] = Field(default=None, alias="otherContribute")
    other_contribute_detail: Optional[List[ContributeDetail]] = Field(default=None, alias="otherContributeDetail")
    purchase_ant_contribute: Optional[StrictStr] = Field(default=None, alias="purchaseAntContribute")
    purchase_buyer_contribute: Optional[StrictStr] = Field(default=None, alias="purchaseBuyerContribute")
    purchase_merchant_contribute: Optional[StrictStr] = Field(default=None, alias="purchaseMerchantContribute")
    template_id: Optional[StrictStr] = Field(default=None, alias="templateId")
    type: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["amount", "id", "memo", "merchantContribute", "name", "otherContribute", "otherContributeDetail", "purchaseAntContribute", "purchaseBuyerContribute", "purchaseMerchantContribute", "templateId", "type"]

    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 VoucherDetail 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 other_contribute_detail (list)
        _items = []
        if self.other_contribute_detail:
            for _item_other_contribute_detail in self.other_contribute_detail:
                if _item_other_contribute_detail:
                    _items.append(_item_other_contribute_detail.to_dict())
            _dict['otherContributeDetail'] = _items
        # set to None if amount (nullable) is None
        # and model_fields_set contains the field
        if self.amount is None and "amount" in self.model_fields_set:
            _dict['amount'] = 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 memo (nullable) is None
        # and model_fields_set contains the field
        if self.memo is None and "memo" in self.model_fields_set:
            _dict['memo'] = None

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

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

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

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

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

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

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

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

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

        _obj = cls.model_validate({
            "amount": obj.get("amount"),
            "id": obj.get("id"),
            "memo": obj.get("memo"),
            "merchantContribute": obj.get("merchantContribute"),
            "name": obj.get("name"),
            "otherContribute": obj.get("otherContribute"),
            "otherContributeDetail": [ContributeDetail.from_dict(_item) for _item in obj["otherContributeDetail"]] if obj.get("otherContributeDetail") is not None else None,
            "purchaseAntContribute": obj.get("purchaseAntContribute"),
            "purchaseBuyerContribute": obj.get("purchaseBuyerContribute"),
            "purchaseMerchantContribute": obj.get("purchaseMerchantContribute"),
            "templateId": obj.get("templateId"),
            "type": obj.get("type")
        })
        return _obj


