package com.pixelnx.localhelp.ui.signup;

import android.content.Context;


import android.util.Log;
import android.widget.Toast;



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

import com.androidnetworking.interfaces.StringRequestListener;

import com.pixelnx.localhelp.utils.Consts;

import org.json.JSONException;
import org.json.JSONObject;

public class PreRegister {
    Context mContext;
    RegisterInterface baseInterface;


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

    void apiRegister(String email, String nme, String mblNum, String pass, String address, String lati, String longitude) {


        AndroidNetworking.post(Consts.Status.BASE_URL + Consts.Status.REGISTER_USER_API)
                .addBodyParameter("u_email", email)
                .addBodyParameter("u_name", nme)
                .addBodyParameter("u_mobile",mblNum)
                .addBodyParameter("u_pwd", pass)
                .addBodyParameter("address", address)
                .addBodyParameter("u_latitude", lati)
                .addBodyParameter("u_longitude", longitude)
                .addBodyParameter("user_type", "2")
                .setPriority(Priority.IMMEDIATE)
                .build()
                .getAsString(new StringRequestListener() {
                    @Override
                    public void onResponse(String response) {


                        try {
                            JSONObject jsonObject=new JSONObject(response);
                            if(jsonObject.getString("status").contains("1")) {
                                baseInterface.result(""+jsonObject.getString("data"));
                            }
                                Toast.makeText(mContext, "" + jsonObject.getString("msg"), Toast.LENGTH_SHORT).show();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onError(ANError anError) {
                        Toast.makeText(mContext,""+anError,Toast.LENGTH_SHORT).show();

                    }
                });



    }


    public interface RegisterInterface {

        void result(String result);

    }


}
