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.pushidregistration.PushIdRegistration;
import io.trustbuilder.mfa.lib.usecase.definition.pushidregistration.PushIdRegistrationParams;

public class PushIdRegistrationActivity extends TrustBuilderActivity {
    private String pushId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: PushIdRegistrationUseCase");
        if (getIntent() != null) {
            this.pushId = getIntent().getStringExtra("FCM_TOKEN");
        }
        setTitle(this.getClass().getSimpleName());
        setContentView(R.layout.activity_register_push_id);
        this.proceed = this.findViewById(R.id.proceed_RegisterPushId);
        this.result = this.findViewById(R.id.result_RegisterPushId);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: PushIdRegistrationUseCase");
        this.proceed.setOnClickListener(v -> {
            PushIdRegistrationParams request = new PushIdRegistrationParams(this.pushId);
            try {
                PushIdRegistration pushIdRegistration = mfaLib.startPushIdRegistration(request);
                displayJsonResult(pushIdRegistration.execute());
            } catch (Exception e) {
                displayException(e);
            }
        });
    }
}