import json

from typing import (
    Any,
    Dict,
    Union
)


class CancelPaymentOrderData(object):
    def __init__(
        self,
        data    # type: Dict[str, Any[Union[int, str, Dict]]]
    ):
        # type: (...) -> None

        tender_detail = data.get("tenderDetail", {})

        self.pos_id = data.get("posId", 0)
        self.order_id = data.get("orderId", None)
        self.fiscal_date = data.get("fiscalDate", "")
        self.fiscal_time = data.get("fiscalTime", "")
        self.tender_type = data.get("tenderType", "")
        self.tender_amount = float(data.get("tenderAmount", 0))
        self.nsu_host = tender_detail.get("NsuHost", "")
        self.card_number = tender_detail.get("CardNumber", "")
        self.tender_id = data.get("tenderId", None)
        self.tenders = json.dumps(tender_detail)
        self.operator_id = data.get("operatorId", None)
        self.electronic_type = data.get("electronicType", None)
        self.auth_code = tender_detail.get("AuthCode", None)
        self.media = tender_detail.get("Media", "")

    def __repr__(
        self
    ):
        # type: (...) -> str

        object_cancel = """
            CancelPaymentData(
                pos_id={},
                order_id={}, 
                fiscal_date="{}",
                fiscal_time="{}",
                tender_type={},
                tender_amount={},
                nsu_host="{}",
                card_number="{}",
                tender_id={},
                tenders="{}",
                operator_id={},
                electronic_type={}
                electronic_type="{}"
                media="{}"
            )
        """

        return object_cancel.format(
            self.pos_id,
            self.order_id,
            self.fiscal_date,
            self.fiscal_time,
            self.tender_type,
            self.tender_amount,
            self.nsu_host,
            self.card_number,
            self.tender_id,
            self.tenders,
            self.operator_id,
            self.electronic_type,
            self.auth_code,
            self.media
        )

    def __str__(
        self
    ):
        # type: (...) -> str
        return self.__repr__()
