# coding: utf-8

"""
Payment API

API for accepting payments and storing subscriptions

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 pydantic import (
    BaseModel,
    ConfigDict,
    Field,
    StrictBool,
    StrictFloat,
    StrictInt,
    StrictStr,
)
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self


class NowCreateInvoiceReq(BaseModel):
    """
    Request model for creating a payment invoice.  Creates a payment link where the customer can complete the payment. With this method, the customer is required to follow the generated url to complete the payment.  https://documenter.getpostman.com/view/7907941/2s93JusNJt#f5e4e645-dce2-4b06-b2ca-2a29aaa5e845
    """  # noqa: E501

    price_amount: Union[StrictFloat, StrictInt] = Field(
        description="Amount to pay in fiat currency"
    )
    price_currency: StrictStr = Field(
        description="Fiat currency for the price (usd, eur, etc)"
    )
    pay_currency: Optional[StrictStr] = None
    ipn_callback_url: Optional[StrictStr] = None
    order_id: Optional[StrictStr] = None
    order_description: Optional[StrictStr] = None
    success_url: Optional[StrictStr] = None
    cancel_url: Optional[StrictStr] = None
    partially_paid_url: Optional[StrictStr] = None
    is_fixed_rate: Optional[StrictBool] = None
    is_fee_paid_by_user: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = [
        "price_amount",
        "price_currency",
        "pay_currency",
        "ipn_callback_url",
        "order_id",
        "order_description",
        "success_url",
        "cancel_url",
        "partially_paid_url",
        "is_fixed_rate",
        "is_fee_paid_by_user",
    ]

    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 NowCreateInvoiceReq 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,
        )
        # set to None if pay_currency (nullable) is None
        # and model_fields_set contains the field
        if self.pay_currency is None and "pay_currency" in self.model_fields_set:
            _dict["pay_currency"] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "price_amount": obj.get("price_amount"),
                "price_currency": obj.get("price_currency"),
                "pay_currency": obj.get("pay_currency"),
                "ipn_callback_url": obj.get("ipn_callback_url"),
                "order_id": obj.get("order_id"),
                "order_description": obj.get("order_description"),
                "success_url": obj.get("success_url"),
                "cancel_url": obj.get("cancel_url"),
                "partially_paid_url": obj.get("partially_paid_url"),
                "is_fixed_rate": obj.get("is_fixed_rate"),
                "is_fee_paid_by_user": obj.get("is_fee_paid_by_user"),
            }
        )
        return _obj
