package com.pixelnx.localhelp.ui.login;

import android.content.Context;


import android.widget.Toast;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;


import com.pixelnx.localhelp.model.ModelUserData;

import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;



public class PreLogin {

    Context mContext;
    RegisterInterface baseInterface;


    public PreLogin(Context mContext, RegisterInterface baseInterface) {
        this.mContext = mContext;
        this.baseInterface = baseInterface;
    }

    void apiLogin( String mblNum, String pass) {



        AndroidNetworking.post(Consts.Status.BASE_URL + Consts.Status.SIGNIN_API)
                .addBodyParameter("mobile",mblNum)
                .addBodyParameter("password", pass)
                .setPriority(Priority.IMMEDIATE)
                .build()
                .getAsObject(ModelUserData.class, new ParsedRequestListener<ModelUserData>() {
                    @Override
                    public void onResponse(ModelUserData response) {
                        Toast.makeText(mContext,""+response.getMsg(),Toast.LENGTH_SHORT).show();
                        if(response.getStatus().contains("1")) {

                            SharedPref sharedPref = SharedPref.getInstance(mContext);
                            sharedPref.setBooleanValue(Consts.Status.IS_REGIS,true);
                            SharedPref.setUser(Consts.Status.SP,response);
                            baseInterface.result("");
                        }else{
                            if(response.getMsg().contains("Your account has been disabled please contact to admin")){
                            baseInterface.result(""+response.getMsg());}
                        }


                    }

                    @Override
                    public void onError(ANError anError) {

                        Toast.makeText(mContext,"Something went wrong",Toast.LENGTH_SHORT).show();
                    }
                });







    }


    public interface RegisterInterface {
        void result(String result);

    }
}
