# 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, Field, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class ApplicationDetailsItem(BaseModel):
    """
    Object representing item replacement.
    """ # noqa: E501
    source_index: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Index number of the source item that is replaced. The enumeration starts from `0`, which represents the first item in the request, e.g., if the replaced item is passed as the second in the request, `source_index` equals `3`.")
    source_applied_quantity: Optional[Annotated[int, Field(le=-1, strict=True)]] = Field(default=None, description="Number of source units that are replaced.")
    source_applied_quantity_amount: Optional[Annotated[int, Field(le=0, strict=True)]] = Field(default=None, description="Amount equal to the price of the units that are replaced. Determines the change of the amount of the source item quantity.")
    target_index: Optional[StrictInt] = Field(default=None, description="Index number of the target item that is a replacement of the source item. The enumeration continues the values for the order items, e.g. if there are three items in the request, `target_index` equals `3`, as enumeration starts from `0`.")
    target_applied_quantity: Optional[StrictInt] = Field(default=None, description="Number of added target units that are replacements.")
    target_applied_quantity_amount: Optional[StrictInt] = Field(default=None, description="Amount equal to the price of the units that are replacements. Determines the change in the amount of the target item quantity.")
    target_applied_discount_amount: Optional[StrictInt] = Field(default=None, description="Discount amount applied to the target item with regard to the replacement. Equals the `target_applied_quantity_amount` minus `source_applied_quantity_amount`.")
    __properties: ClassVar[List[str]] = ["source_index", "source_applied_quantity", "source_applied_quantity_amount", "target_index", "target_applied_quantity", "target_applied_quantity_amount", "target_applied_discount_amount"]

    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 ApplicationDetailsItem 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "source_index": obj.get("source_index"),
            "source_applied_quantity": obj.get("source_applied_quantity"),
            "source_applied_quantity_amount": obj.get("source_applied_quantity_amount"),
            "target_index": obj.get("target_index"),
            "target_applied_quantity": obj.get("target_applied_quantity"),
            "target_applied_quantity_amount": obj.get("target_applied_quantity_amount"),
            "target_applied_discount_amount": obj.get("target_applied_discount_amount")
        })
        return _obj


