# -*- coding: utf-8 -*-
from logging import Logger

from cfgtools import Group
from modelcommon.model import SitefResponse

from dialogmanager import DialogManager
from mbcontextmessagehandler import MbContextMessageBus
from typing import (
    Any,
    Union,
    Optional,
)

from paymentprocessor import PaymentProcessor
from _CapptaProcessor import CapptaProcessor
from model import (
    CancelPaymentOrderData,
    ConfirmFinishPaymentData,
    TestConnectionData,
    FinishPaymentData,
)
from util import Cache


class CapptaCreditPaymentProcessor(PaymentProcessor):
    def __init__(
        self,
        message_bus,        # type: MbContextMessageBus
        dialog_manager,     # type: DialogManager
        config,             # type: Group
        logger,             # type: Logger
        cache,              # type: Cache
    ):
        # type: (...) -> None

        super(CapptaCreditPaymentProcessor, self).__init__(message_bus, dialog_manager, config, logger, cache)
        self.cappta_processor = CapptaProcessor(message_bus, dialog_manager, config, logger, cache)

    def connection_status(
        self,
        test_connection_data    # type: TestConnectionData
    ):
        # type: (...) -> bool

        return self.cappta_processor.connection_status(test_connection_data=test_connection_data)

    def add_payment(self, start_payment_data):
        return self.cappta_processor.add_payment(
            start_payment_data=start_payment_data,
        )

    def cancel_payment_order(
        self,
        cancel_payment_order_data,  # type: CancelPaymentOrderData
        additional_params="",       # type: Optional[str]
    ):
        # type: (...) -> Any[Union[SitefResponse, str]]

        return self.cappta_processor.cancel_payment_order(cancel_payment_order_data=cancel_payment_order_data)

    def cancel_payment(self):
        return self.cappta_processor.cancel_payment()

    def finish_payment(
        self,
        finish_payment_data,        # type: FinishPaymentData
    ):
        # type: (...) -> bool

        return self.cappta_processor.finish_payment(
            finish_payment_data=finish_payment_data,
        )

    def confirm_finish_payment(
        self,
        confirm_finish_payment_data     # type: ConfirmFinishPaymentData
    ):
        # type: (...) -> None

        self.cappta_processor.confirm_finish_payment(confirm_finish_payment_data=confirm_finish_payment_data)

    def get_name(self):
        return self.cappta_processor.get_name()

    def get_document(
        self,
        pos_id      # type: str
    ):
        # type: (...) -> str

        return self.cappta_processor.get_document(pos_id)

    def stop(self):
        self.cappta_processor.stop()

    def get_last_receipt(
        self,
        eft_processor,    # type: str
    ):
        # type: (...) -> Optional[str]

        return self.cappta_processor.get_last_receipt(eft_processor=eft_processor)
