package kz.com.aman.kassa.bank;

import android.widget.Toast;
import ru.m4bank.mpos.library.external.authorization.AuthorizationCallbackHandler;
import ru.m4bank.mpos.service.authorization.network.AuthorizationResponse;


public class AuthorizationCallbackHandlerImpl implements AuthorizationCallbackHandler {
    private final M4BankActivity activity;

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

    @Override
    public void onLoginAndPasswordRequested() {
        activity.getClientInterface().getAuthorizationManager().sendLoginAndPassword(activity.getLogin(), activity.getPassword());
    }


    @Override
    public void onCompleted(ru.m4bank.mpos.service.result.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());
    }

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