package kz.com.aman.kassa.handler;

import android.widget.Toast;

import com.google.gson.Gson;

import io.flutter.plugin.common.MethodChannel;
import kz.com.aman.kassa.MainActivity;
import kz.com.aman.kassa.model.AmanDao;
import ru.m4bank.mpos.library.external.configuration.CheckConnectionCallbackHandler;
import ru.m4bank.mpos.service.result.CheckConnectionExternalResult;

public class ConnectionCheckHandlerImpl implements CheckConnectionCallbackHandler {
    private final Gson gson = new Gson();
    private final MainActivity activity;
    private final MethodChannel.Result result;

    public ConnectionCheckHandlerImpl(MainActivity activity, MethodChannel.Result result) {
        this.activity = activity;
        this.result = result;
    }

    @Override
    public void onCompleted(CheckConnectionExternalResult result) {
        activity.runOnUiThread(() -> {
                    //Toast.makeText(activity, result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()) + " " + result.isOnlineRegistration(), Toast.LENGTH_SHORT).show();
                    AmanDao<String> dao = new AmanDao<>();
                    dao.setSuccess(true);
                    dao.setMsg("OK");
                    this.result.success(gson.toJson(dao));
                }
        );
    }


    @Override
    public void onWrongApiCalled() {
        activity.runOnUiThread(() -> {
            //Toast.makeText(activity, "Wrong method has been called", Toast.LENGTH_SHORT).show();
            AmanDao<String> dao = new AmanDao<>();
            dao.setSuccess(false);
            dao.setMsg("error");
            this.result.success(gson.toJson(dao));

        });
    }
}
