<?php

namespace App\Services;

use GuzzleHttp\Client as HTTPClient;
//use \\CoreServiceApi;

class ResetPassword extends CoreServiceApi
{


 public static function procResetPassword($data)
    {
	    $res =[];
        $resArray =[];
	    $mode = (int) $data['mode'];
        log_message('critical', "ResetPassword=>Mode ====>===>".$data['mode'] );
        log_message('critical', "ResetPassword=DATA====>===>".json_encode($data) );

        switch($mode){

            case 100:
                $arr = array('mode' => $mode, 'email' => $data['username']); 
                $data_json = json_encode($arr);
                $res = self::NodeServiceApi('user/reset-password', $data_json);
               // $res->internal_return = 0;
               $resArray = json_decode($res, true);
               $resArray['internal_return'] = 0;
                log_message('critical', "ResetPassword=>Mode ====>===> Node return" );
            break;

            case 200:
                /*
                CRITICAL - 2022-04-27 19:32:50 --> API-WAS CALLED user
CRITICAL - 2022-04-27 19:32:51 --> API-WAS CALLED user
CRITICAL - 2022-04-27 19:32:51 --> username=>ses66181@gmail.com
CRITICAL - 2022-04-27 19:32:51 --> mode=>200
CRITICAL - 2022-04-27 19:32:51 --> reset_pin=>123456
CRITICAL - 2022-04-27 19:32:51 --> newpass=>
CRITICAL - 2022-04-27 19:32:51 --> reset_key=>
CRITICAL - 2022-04-27 19:32:51 --> API-WAS CALLED user 009=>resetpass
CRITICAL - 2022-04-27 19:32:51 --> username=>ses66181@gmail.com
CRITICAL - 2022-04-27 19:32:51 --> mode=>200
CRITICAL - 2022-04-27 19:32:51 --> reset_pin=>123456
CRITICAL - 2022-04-27 19:32:51 --> newpass=>
CRITICAL - 2022-04-27 19:32:51 --> reset_key=>
CRITICAL - 2022-04-27 19:32:51 --> Undefined variable: mode
                */
                $arr = array('mode' => $mode, 'email' => $data['username'], 'resetPin'=>$data['reset_pin'] );
                $data_json =  json_encode($arr);
                $res = self::NodeServiceApi('/user/reset-password', $data_json);
                $resArray = json_decode($res, true);
                $resArray['retval'] = 0;
                $resArray['status_message'] = "Enter new password";
                log_message('critical', "ResetPassword=>Mode ====>===> 200 Node return" );
            break;

            case 300:
/*

CRITICAL - 2022-04-27 20:03:21 --> API-WAS CALLED user
CRITICAL - 2022-04-27 20:03:22 --> API-WAS CALLED user
CRITICAL - 2022-04-27 20:03:22 --> username=>ses66181@gmail.com
CRITICAL - 2022-04-27 20:03:22 --> mode=>300
CRITICAL - 2022-04-27 20:03:22 --> reset_pin=>486668
CRITICAL - 2022-04-27 20:03:22 --> newpass=>may12002
CRITICAL - 2022-04-27 20:03:22 --> API-WAS CALLED user 009=>resetpass
CRITICAL - 2022-04-27 20:03:22 --> username=>ses66181@gmail.com
CRITICAL - 2022-04-27 20:03:22 --> mode=>300
CRITICAL - 2022-04-27 20:03:22 --> reset_pin=>486668
CRITICAL - 2022-04-27 20:03:22 --> newpass=>may12002
CRITICAL - 2022-04-27 20:03:22 --> ResetPassword=>Mode ====>===>300
CRITICAL - 2022-04-27 20:03:22 --> ResetPassword=DATA====>===>{"username":"ses66181@gmail.com","mode":300,"reset_pin":"486668","newpass":"may12002"}
CRITICAL - 2022-04-27 20:03:22 --> Out******* API-WAS CALLED user 009=>resetpass


curl --location --request POST 'http://10.20.30.26:8000/api/v1/user/reset-password' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "lviet@float.sg",
    "newPassword": "123456",
    "resetPin": "505038",
    "resetKey":"5e3580998333dd6ce0805a66c8073ad1",
    "mode":300
}'
*/

                $arr = array('mode' => $mode, 'email' => $data['username'], 
                            'resetPin'=>$data['reset_pin'], 
                            'newPassword'=>$data['newpass'],
                            "resetKey"=>"5e3580998333dd6ce0805a66c8073ad1" );
                            
                $data_json =  json_encode($arr);
                $res = self::NodeServiceApi('/user/reset-password', $data_json);
                $resArray = json_decode($res, true);
                $resArray['retval'] = 0;
                $resArray['status_message'] = "Enter new password";
                log_message('critical', "ResetPassword=>Mode ====>===> 3200 Node return" );
            break;
        }

        return $resArray;
    }

}
