package kz.com.aman.kassa.bank;

import android.widget.Toast;

import java.util.List;

import ru.m4bank.mpos.library.external.transactions.PrintingCallbackHandler;
import ru.m4bank.mpos.service.data.FiscalStatusData;
import ru.m4bank.mpos.service.data.PrinterBaseData;
import ru.m4bank.mpos.service.data.PrinterErrorData;
import ru.m4bank.mpos.service.hardware.printer.dto.data.PrintingType;
import ru.m4bank.mpos.service.result.PrinterResult;
import ru.m4bank.mpos.service.result.Result;
import timber.log.Timber;

public class PrintingCallbackHandlerImpl implements PrintingCallbackHandler<Result, PrinterResult<PrinterErrorData, PrinterBaseData>> {

    private final M4BankActivity activity;

    public PrintingCallbackHandlerImpl(M4BankActivity activity) {
        this.activity = activity;
    }

    @Override
    public void onRequestedReportZ() {
        Timber.i("onRequestedReportZ");
        activity.getClientInterface().getPrinterManager().printReport(this, PrintingType.Z_REPORT);
    }

    @Override
    public void onCompletedPrinting(PrinterResult printerResult) {
        Timber.i("onCompletedPrinting = " + printerResult);
        activity.runOnUiThread(() -> Toast.makeText(activity, "onCompletedPrinting = " + printerResult, Toast.LENGTH_SHORT).show());
    }

    @Override
    public void onStatusFiscalModule(FiscalStatusData fiscalStatusData) {

    }

    @Override
    public void onPrinterForRegistrationGettingCompleted() {
        Timber.i("onPrinterForRegistrationGettingCompleted");
        activity.runOnUiThread(() -> Toast.makeText(activity, "Saved printer - " + activity.getClientInterface().getPrinterManager().isSavedPrinterName(), Toast.LENGTH_SHORT).show());
    }

    @Override
    public void onNoBoundedPrinterFound() {
        Timber.i("onNoBoundedPrinterFound");
    }

    @Override
    public void onPrinterToUseSelectionRequested(List printerList) {
        Timber.i("printerList = " + printerList);
        activity.getClientInterface().getPrinterManager().selectPrinter(printerList.get(0).toString());
    }

    @Override
    public void onCompleted(Result result) {
        Timber.i("onCompleted = " + result.getResultType().toString());
    }

    @Override
    public void onWrongApiCalled() {
        Timber.i("onWrongApiCalled");
    }

    @Override
    public void onRepeat(int attemptNumber) {
        Timber.i("onRepeat");
    }

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