package io.trustbuilder.mfa.android.demoapp.screen;

import android.os.Bundle;
import android.util.Log;

import io.trustbuilder.mfa.android.demoapp.R;
import io.trustbuilder.mfa.lib.usecase.definition.pendingauthsessionsretrieval.PendingAuthSessionsRetrieval;
import io.trustbuilder.mfa.lib.usecase.definition.pendingauthsessionsretrieval.PendingAuthSessionsRetrievalParams;

public class PendingAuthSessionsRetrievalActivity extends TrustBuilderActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: PendingAuthSessionsRetrievalUseCase");
        setTitle(this.getClass().getSimpleName());
        setContentView(R.layout.activity_get_pending_auth_sessions);
        this.proceed = this.findViewById(R.id.proceed_GetPendingAuthSessions);
        this.tknAlias = this.findViewById(R.id.tknAlias_GetPendingAuthSessions);
        this.result = this.findViewById(R.id.result_GetPendingAuthSessions);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: PendingAuthSessionsRetrievalUseCase");
        this.proceed.setOnClickListener(v -> {
            if (checkMandatoryField(tknAlias, "tknAlias")) return;
            PendingAuthSessionsRetrievalParams request = new PendingAuthSessionsRetrievalParams(tknAlias.getText().toString());
            try {
                PendingAuthSessionsRetrieval pendingAuthSessionsRetrieval = mfaLib.startPendingAuthSessionsRetrieval(request);
                displayJsonResult(pendingAuthSessionsRetrieval.execute());
            } catch (Exception e) {
                displayException(e);
            }
        });
    }
}