package kz.com.aman.kassa.bank;

import android.widget.Toast;

import java.util.List;

import ru.m4bank.mpos.library.external.transactions.GetTransactionDetailsCallbackHandler;
import ru.m4bank.mpos.library.external.transactions.GetTransactionsListCallbackHandler;
import ru.m4bank.mpos.service.data.dynamic.objects.Transaction;
import ru.m4bank.mpos.service.result.Result;

class GetTransactionListForRefundCallbackHandlerImpl implements GetTransactionDetailsCallbackHandler<Result>, GetTransactionsListCallbackHandler<Result> {
    private final M4BankActivity activity;
    private final CardRefundCallbackHandlerImpl cardRefundCallbackHandler;

    GetTransactionListForRefundCallbackHandlerImpl(M4BankActivity activity, CardRefundCallbackHandlerImpl cardRefundCallbackHandler) {
        this.cardRefundCallbackHandler = cardRefundCallbackHandler;
        this.activity = activity;
    }

    @Override
    public void onTransactionDetailsReceived(Transaction transaction) {
        activity.runOnUiThread(() -> Toast.makeText(activity, "Transaction details received: " + transaction, Toast.LENGTH_SHORT)
             .show());
    }
    
    @Override
    public void onSuccessStatusTransaction(Transaction transaction) {
        
    }
    
    @Override
    public void onErrorStatusTransaction() {
        
    }
    
    @Override
    public void onTransactionsListReceived(List<Transaction> transactionList) {
        cardRefundCallbackHandler.onTransactionsListReceived(transactionList);
    }

    @Override
    public void notAuthorized() {
        activity.runOnUiThread(() -> Toast.makeText(activity, "Not authorized", Toast.LENGTH_SHORT).show());
    }

    @Override
    public void onCompleted(Result result) {
        activity.runOnUiThread(() -> Toast.makeText(activity, result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()), Toast.LENGTH_SHORT)
             .show());
    }

    @Override
    public void onWrongApiCalled() {
        activity.runOnUiThread(() -> Toast.makeText(activity, "Wrong method has been called", Toast.LENGTH_SHORT).show());
    }

    @Override
    public void onRepeat(int attemptNumber) {
        activity.runOnUiThread(() -> Toast.makeText(activity, "Repeat attempt number " + attemptNumber, Toast.LENGTH_SHORT).show());
    }
}
