package com.yono.messeripos;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageButton;

import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.UsersService;
import com.yono.messeripos.models.ForgotPasswordModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ForgotPasswordActivity extends AppCompatActivity {
    ImageButton btnReset;
    ForgotCode forgotCode;
    ForgotPasswordModels forgotPasswordModels;
    Utils utils = new Utils();
    Client client=new Client();
    UsersService usersService;
    EditText formForgot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forgot_password);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow();
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

        forgotPasswordModels = new ForgotPasswordModels();

//        bind UI
        btnReset = findViewById(R.id.btn_reset_password);
        formForgot = findViewById(R.id.forgotEmail);

        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                forgotPasswordModels.setEmail(formForgot.getText().toString());
                forgotPasswordModels.setMessage(utils.getRandomNumberString());

                usersService = client.Client(UsersService.class);
                usersService.postForgotPassword(forgotPasswordModels).enqueue(new Callback<DataResponse>() {
                    @Override
                    public void onResponse(Call<DataResponse> call, Response<DataResponse> response) {
                        forgotCode = new ForgotCode(ForgotPasswordActivity.this, response.body());
                        forgotCode.show(getSupportFragmentManager(), "forgot code");
                    }

                    @Override
                    public void onFailure(Call<DataResponse> call, Throwable t) {

                    }
                });
            }
        });
    }
}