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

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

import io.trustbuilder.mfa.android.demoapp.R;
import io.trustbuilder.mfa.lib.usecase.definition.securetokenfriendlynameupdate.SecureTokenFriendlyNameUpdate;
import io.trustbuilder.mfa.lib.usecase.definition.securetokenfriendlynameupdate.SecureTokenFriendlyNameUpdateParams;

public class SecureTokenFriendlyNameUpdateActivity extends TrustBuilderActivity {
    private EditText tknName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: SecureTokenFriendlyNameUpdateUseCase");
        setTitle(this.getClass().getSimpleName());
        setContentView(R.layout.activity_update_secure_token_friendly_name);
        this.proceed = this.findViewById(R.id.proceed_FrendlyName);
        this.tknAlias = this.findViewById(R.id.tknAlias_FrendlyName);
        this.result = this.findViewById(R.id.result_FrendlyName);
        this.tknName = this.findViewById(R.id.tknName_FrendlyName);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: SecureTokenFriendlyNameUpdateUseCase");
        this.proceed.setOnClickListener((v) -> {
            if (checkMandatoryField(tknAlias, "tknAlias")) return;
            if (checkMandatoryField(tknName, "tknName")) return;
            SecureTokenFriendlyNameUpdateParams request = new SecureTokenFriendlyNameUpdateParams(tknAlias.getText().toString(), tknName.getText().toString());
            try {
                SecureTokenFriendlyNameUpdate secureTokenFriendlyNameUpdate = mfaLib.startSecureTokenFriendlyNameUpdate(request);
                displayJsonResult(secureTokenFriendlyNameUpdate.execute());
            } catch (Exception e) {
                displayException(e);
            }
        });
    }
}