<?php
	defined('BASEPATH')OR exit('No direct script access allowed');
	header('Content-Type: text/html; charset=utf-8');
	
	if(isset($_SERVER['HTTP_ORIGIN'])) {
		header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
		header('Access-Control-Allow-Credentials: true');
		header('Access-Control-Max-Age: 86400'); // cache for 1 day
	}
	
	if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
		if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
		header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
		if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
		header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
		exit(0);
	}
	
	class Webservice extends CI_Controller {
		public function __construct() {
			parent::__construct();
			$this->load->model('Webservice_model');
		}
//User Signup
		public function user_signup(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);

			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_name']) || empty($postData['user_name'])){
				$err = 1;
				$msg = 'Provide a valid Username';
			} 
			else if(!isset($postData['user_password']) || empty($postData['user_password'] = md5($postData['user_password']))){
				$err = 1;
				$msg = 'Provide a Password';
			}
			else if(!isset($postData['user_email']) || empty($postData['user_email'])){
				$err = 1;
				$msg = 'Provide valid Email';
			}
			else if(!isset($postData['user_phonecode']) || empty($postData['user_phonecode'])){
				$err = 1;
				$msg = 'Provide Phone Code';
			}
			else if(!isset($postData['user_phonenumber']) || empty($postData['user_phonenumber'])){
				$err = 1;
				$msg = 'Provide valid Phone Number';
			}
			else if(!isset($postData['user_country']) || empty($postData['user_country'])){
				$err = 1;
				$msg = 'Provide valid Country';
			}
			else if(!isset($postData['user_area']) || empty($postData['user_area'])){
				$err = 1;
				$msg = 'Provide valid Area';
			}
			else if(!isset($postData['user_address']) || empty($postData['user_address'])){
				$err = 1;
				$msg = 'Provide an Address';
			}
			else if(!isset($postData['user_lat']) || empty($postData['user_lat'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			else if(!isset($postData['user_lng']) || empty($postData['user_lng'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			else if(!isset($postData['device_id']) || empty($postData['device_id'])){
				$err = 1;
				$msg = 'Device Id is required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$custResp = $this->Webservice_model->createCustomer($postData);
			if(empty($custResp)){
				echo json_encode($respArr);exit;
			}
			if($custResp == '1'){
				$postData['user_type'] = 1;
				$custResp = $this->Webservice_model->checkCustomerLogin($postData);
				if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
					echo json_encode($respArr);exit;
				}
				if($custResp['status'] == '1'){
					$respArr['data'] = $custResp['data'];
					$respArr['status'] = 'success';
					$respArr['message'] = 'Success';
					echo json_encode($respArr);exit;
				}
			} else if($custResp == '2'){
				$respArr['status'] = '2';
				$respArr['message'] = 'Email Address already in use';
				echo json_encode($respArr);exit;
			} else if($custResp == '3'){
				$respArr['status'] = '2';
				$respArr['message'] = 'Phone already in use';
				echo json_encode($respArr);exit;
			}
			echo json_encode($respArr); exit;
		}
//User Login
		public function user_login(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_email']) || empty($postData['user_email'])){
				$err = 1;
				$msg = 'Provide a valid Email';
			} 
			else if(!isset($postData['user_password']) || empty($postData['user_password'] = md5($postData['user_password']))){
				$err = 1;
				$msg = 'Provide a Password';
			}
			else if(!isset($postData['user_lat']) || empty($postData['user_lat'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			else if(!isset($postData['user_lng']) || empty($postData['user_lng'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			else if(!isset($postData['device_id']) || empty($postData['device_id'])){
				$err = 1;
				$msg = 'Device Id is Required';
			}
			else if(!isset($postData['user_type']) || empty($postData['user_type'])){
				$err = 1;
				$msg = 'User Type is Required';
			}

			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->userLogin($postData);
			echo json_encode($respArr);exit;
		}
//Forgot Password
		public function update_profile(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			} 
			else if(!isset($postData['user_name']) || empty($postData['user_name'])){
				$err = 1;
				$msg = 'Provide a valid Username';
			} 
			// else if(!isset($postData['user_password']) || empty($postData['user_password'] = md5($postData['user_password']))){
			// 	$err = 1;
			// 	$msg = 'Provide a Password';
			// }
			else if(!isset($postData['user_email']) || empty($postData['user_email'])){
				$err = 1;
				$msg = 'Provide valid Email';
			}
			else if(!isset($postData['user_phonecode']) || empty($postData['user_phonecode'])){
				$err = 1;
				$msg = 'Provide Phone Code';
			}
			else if(!isset($postData['user_phonenumber']) || empty($postData['user_phonenumber'])){
				$err = 1;
				$msg = 'Provide valid Phone Number';
			}
			else if(!isset($postData['user_country']) || empty($postData['user_country'])){
				$err = 1;
				$msg = 'Provide valid Country';
			}
			else if(!isset($postData['user_area']) || empty($postData['user_area'])){
				$err = 1;
				$msg = 'Provide valid Area';
			}
			else if(!isset($postData['user_address']) || empty($postData['user_address'])){
				$err = 1;
				$msg = 'Provide an Address';
			}
			else if(!isset($postData['user_lat']) || empty($postData['user_lat'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			else if(!isset($postData['user_lng']) || empty($postData['user_lng'])){
				$err = 1;
				$msg = 'Provide User Location';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$custResp = $this->Webservice_model->updateCustomer($postData);
			if(empty($custResp)){
				echo json_encode($respArr);exit;
			}
			if($custResp == '1'){
				$respArr['status'] = 'success';
				$respArr['message'] = 'Success';
				echo json_encode($respArr);exit;
			} else if($custResp == '2'){
				$respArr['status'] = 'error';
				$respArr['message'] = 'Email Address already in use';
				echo json_encode($respArr);exit;
			} else if($custResp == '3'){
				$respArr['status'] = 'error';
				$respArr['message'] = 'Phone already in use';
				echo json_encode($respArr);exit;
			}else{
				$respArr['status'] = 'error';
				$respArr['message'] = 'Something went wrong..Try Again Later';
				echo json_encode($respArr);exit;
			}
			echo json_encode($respArr); exit;
		}
//upload profilepic
		public function upload_profilePic(){
			header('Content-type: application/json');
			//$postData = $_POST;
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);

			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			

			// if(isset($_FILES) && !empty($_FILES) && isset($_FILES['user_profilepic']) && !empty($_FILES['user_profilepic'])){
			// 	$config = set_upload_service("assets/uploads/customer");
			// 	$this->load->library('upload');
			// 	$config['file_name'] = time()."_".$_FILES['user_profilepic']['name'];
			// 	$this->upload->initialize($config);
			// 	if($this->upload->do_upload('user_profilepic')){
			// 		$upload_data = $this->upload->data();
			// 		$postData['profile_photo'] = $config['upload_path']."/".$upload_data['file_name'];
			// 	}
			// }
			$folderPath = "assets/uploads/customer/";

	        $image_parts = explode(";base64,", $postData['user_profilepic']);

	        $image_type_aux = explode("image/", $image_parts[0]);

	        $image_type = $image_type_aux[1];

	        $image_base64 = base64_decode($image_parts[1]);

	        $file = $folderPath . uniqid() . '.jpg';

	        file_put_contents($file, $image_base64);

	        $postData['profile_photo'] = $file;

			$custResp = $this->Webservice_model->upload_profilePic($postData);
			if($custResp == '1'){
				$respArr = array('status'=>'success','message'=>'Profile Pic Updated Successfully');
			}
			echo json_encode($respArr); exit;
		}
//Forgot Password for user
		public function user_forgetpsw(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(!isset($postData['user_phonenumber']) || empty($postData['user_phonenumber'])){
				$respArr['message'] = 'Phone Number is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['user_countrycode']) || empty($postData['user_countrycode'])){
				$respArr['message'] = 'Country Code is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->user_forgetpsw($postData);
			echo json_encode($respArr); exit;
		}
//OTP for User
		public function user_otp(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['otp']) || empty($postData['otp'])){
				$respArr['message'] = 'OTP is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->user_otp($postData);
			echo json_encode($respArr); exit;
		}
//Resend OTP For User 
		public function user_otp_resend(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['user_phonenumber']) || empty($postData['user_phonenumber'])){
				$respArr['message'] = 'Phone Number is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['user_countrycode']) || empty($postData['user_countrycode'])){
				$respArr['message'] = 'Country Code is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->user_forgetpsw($postData);
			echo json_encode($respArr); exit;
		}
//Get CarVin
		public function get_carVin(){
			header('Content-type: application/json');
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'0','message'=>'Something went wrong.');
			if(empty($postData) || !isset($postData['user_id']) || empty($postData['user_id']) || !isset($postData['car_vinNumber']) || empty($postData['car_vinNumber'])){
				echo json_encode($respArr);exit;
			}
			$settings = getSettings();
			$url = "https://specifications.vinaudit.com/v3/specifications?format=json&key=".urlencode($settings['vin_audit_api'])."&vin=".urlencode($postData['car_vinNumber']);
			if(!empty($url)){
				$vehData=file_get_contents($url);
				if(empty($vehData) || empty($vehData = json_decode($vehData,true))){
					echo json_encode($return_arr);exit;
				}
				if(!isset($vehData['success']) || empty($vehData['success']) || $vehData['success'] == false || ((!isset($vehData['attributes']) || empty($vehData['attributes'])) && 
                	(!isset($vehData['selections']) || empty($vehData['selections'])))){
					$return_arr['status'] = 2;
					$return_arr['message'] = 'No Data Found.';
					echo json_encode($return_arr);exit;
				}
				$vehDetails['vehicle'] = $vehData['attributes']['year'].' '.
                                         	 $vehData['attributes']['make'].' '.
                                         	 $vehData['attributes']['model'];
                $vehDetails['year']    = $vehData['attributes']['year'];
                $vehDetails['make']    = $vehData['attributes']['make'];
                $vehDetails['model']   = $vehData['attributes']['model'];
				$vehDetails['mileage'] = (isset($postData['mileage']) && !empty($postData['mileage']))?$postData['mileage']:'';
				$car_id = $this->Webservice_model->addVehicle($vehDetails,$postData);
				if($car_id){
					$return_arr['status'] = '1';
					$return_arr['data'] = $vehDetails;
				}
			}
			echo json_encode($return_arr);exit;
		}
//Get Most Purchased
		public function get_mostpurchased(){
			header('Content-type: application/json');
			$respArr = $this->Webservice_model->people_most_purchased();
			echo json_encode($respArr); exit;
		}
//Product for User
		public function products_for_user(){
			header('Content-type: application/json');
			$postData = $_GET;
			$respArr = $this->Webservice_model->products_for_user($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Add User Car
		public function add_UserCar(){
			$postData = $_POST;
			$respArr = array('status'=>'error','message'=>'Something went wrong1.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			} 
			else if(!isset($postData['car_VinNumber']) || empty($postData['car_VinNumber'])){
				$err = 1;
				$msg = 'Provide a car Vin Number';
			} 
			else if(!isset($postData['car_brand']) || empty($postData['car_brand'])){
				$err = 1;
				$msg = 'Provide a Car Brand';
			}
			else if(!isset($postData['car_model']) || empty($postData['car_model'])){
				$err = 1;
				$msg = 'Provide a Car Model';
			}
			else if(!isset($postData['car_year']) || empty($postData['car_year'])){
				$err = 1;
				$msg = 'Provide s Car Year';
			}
			else if(!isset($postData['car_milege']) || empty($postData['car_milege'])){
				$err = 1;
				$msg = 'Provide Car Mileage';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$postData['vehicle_image'] = '';
			if(isset($_FILES)&& !empty($_FILES)&& isset($_FILES['car_image'])&& !empty($_FILES['car_image'])){
				$config = set_upload_service("assets/uploads/vehicle");
				$this->load->library('upload');
				$config['file_name'] = time()."_".$_FILES['car_image']['name'];
				$this->upload->initialize($config);
				if($this->upload->do_upload('car_image')){
					$upload_data = $this->upload->data();
					$postData['vehicle_image'] = $config['upload_path']."/".$upload_data['file_name'];
				}
			}
			$respArr = $this->Webservice_model->add_UserCar($postData);
			echo json_encode($respArr);exit;
		}
//Get Main Service List
		public function get_mainservicelist(){
			header('Content-type: application/json');
			$respArr = $this->Webservice_model->get_MainServices();
			echo json_encode($respArr); exit;
		}
//Get Subservice List
		public function get_subservicelist(){
			header('Content-type: application/json');
			$postData = $_GET;
			if(!isset($postData['service_id']) || empty($postData['service_id'])){
				$respArr['status'] = "error";
				$respArr['message'] = 'Provide Service Id';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_subServices($postData['service_id']);
			echo json_encode($respArr); exit;
		}
//Get CarDetails
		public function get_carList(){
			header('Content-type: application/json');
			$postData = $_GET;
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['status'] = "error";
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_carDetails($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Get User Profile
		public function get_userProfile(){
			header('Content-type: application/json');
			$postData = $_GET;
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['status'] = "error";
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_userProfile($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Road Assistance List
		public function road_assistanceList(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_lat']) || empty($postData['user_lat'])){
				$respArr['message'] = 'User Latitude is Required';
				echo json_encode($respArr); exit;
			} 
			else if(!isset($postData['user_lng']) || empty($postData['user_lng'])){
				$respArr['message'] = 'User Longitude is Required';
				echo json_encode($respArr); exit;
			} 
			$respArr = $this->Webservice_model->road_assistanceList($postData);
			echo json_encode($respArr); exit;
		}
//Road Assistance Details  
		public function road_assistanceDetail(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['roadassistant_id']) || empty($postData['roadassistant_id'])){
				$respArr['message'] = 'Road Assistant Id is Required';
				echo json_encode($respArr); exit;
			}
			$respArr = $this->Webservice_model->road_assistanceDetail($postData['roadassistant_id']);
			echo json_encode($respArr); exit;
		}
//Book Road Assistance
		public function book_roadassistance(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			} 
			else if(!isset($postData['user_lat']) || empty($postData['user_lat'])){
				$err = 1;
				$msg = 'Provide User Longitude';
			} 
			else if(!isset($postData['user_lng']) || empty($postData['user_lng'])){
				$err = 1;
				$msg = 'Provide User Latitude';
			}
			else if(!isset($postData['roadassistance_id']) || empty($postData['roadassistance_id'])){
				$err = 1;
				$msg = 'Provide Road Assistant Id';
			}
			else if(!isset($postData['user_carId']) || empty($postData['user_carId'])){
				$err = 1;
				$msg = 'Provide User Car Id';
			}
			else if(!isset($postData['date']) || empty($postData['date'])){
				$err = 1;
				$msg = 'Provide Booking Date';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->book_roadassistance($postData);
			echo json_encode($respArr); exit;
		}
//Road Assistance Detail History
		public function road_assistanceDetail_history(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(!isset($postData['roadassistant_id']) || empty($postData['roadassistant_id'])){
				$respArr['message'] = 'Road Assistant Id is Required';
				echo json_encode($respArr); exit;
			}
			$respArr = $this->Webservice_model->road_assistanceDetail_history($postData['roadassistant_id']);
			echo json_encode($respArr); exit;
		}
//Road Assistance Request Status
		public function status_roadassistancerequest(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['roadservice_requestId']) || empty($postData['roadservice_requestId'])){
				$respArr['message'] = 'Road Assistant Id is Required';
				echo json_encode($respArr); exit;
			}else if(!isset($postData['status'])){
				$respArr['message'] = 'Status is Required';
				echo json_encode($respArr); exit;
			}
			$respArr = $this->Webservice_model->status_roadassistancerequest($postData);
			echo json_encode($respArr); exit;
		}
//Road Assistance Request List
		public function road_assistancerequestlist(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr); exit;
			}
			$respArr = $this->Webservice_model->road_assistancerequestlist($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Write Review
		public function write_review(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			}
			else if(!isset($postData['review_rate']) || empty($postData['review_rate'])){
				$err = 1;
				$msg = 'Rating is Required';
			}
			else if(!isset($postData['reviewing_type']) || empty($postData['reviewing_type'])){
				$err = 1;
				$msg = 'Reviewing Type is Required';
			}
			else if(!isset($postData['review_caption']) || empty($postData['review_caption'])){
				$err = 1;
				$msg = 'Review Caption is Required';
			}
			else if(!isset($postData['review_description']) || empty($postData['review_description'])){
				$err = 1;
				$msg = 'Review Description is Required';
			}
			else if(!isset($postData['booking_id']) || empty($postData['booking_id'])){
				$err = 1;
				$msg = 'Booking Id is Required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->write_review($postData);
			echo json_encode($respArr); exit;
		}
//User Request Service
		public function user_requestService(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			}
			else if(!isset($postData['subservice_id']) || empty($postData['subservice_id'])){
				$err = 1;
				$msg = 'Sub Service Id is Required';
			}
			else if(!isset($postData['booking_date']) || empty($postData['booking_date'])){
				$err = 1;
				$msg = 'Booking Date is Required';
			}
			else if(!isset($postData['car_id']) || empty($postData['car_id'])){
				$err = 1;
				$msg = 'Car Id is Required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->user_requestService($postData);
			echo json_encode($respArr); exit;
		}
//Get User Booked Service Details
		public function get_userbookedServiceDetails(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->user_bookedService($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Get Garage Details
		public function get_garageDetails(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['req_id']) || empty($postData['req_id'])){
				$respArr['message'] = 'Garage Request Id is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['garage_id']) || empty($postData['garage_id'])){
				$respArr['message'] = 'Garage Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_garageDetails($postData);
			echo json_encode($respArr); exit;
		}
//Book Garage
		public function book_garage(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['resp_id']) || empty($postData['resp_id'])){
				$respArr['message'] = 'Response Id is Required';
				echo json_encode($respArr);exit;
			}else if(!isset($postData['req_id']) || empty($postData['req_id'])){
				$respArr['message'] = 'Request Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->book_garage($postData);
			echo json_encode($respArr); exit;
		}
//Search Product
		public function search_product(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['product_keyword']) || empty($postData['product_keyword'])){
				$respArr['message'] = 'Search Keyword is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->search_product($postData['product_keyword']);
			echo json_encode($respArr); exit;
		}
//Product Details
		public function product_detail(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['product_id']) || empty($postData['product_id'])){
				$respArr['message'] = 'Product Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->product_detail($postData['product_id']);
			echo json_encode($respArr); exit;
		}
//Add New Address
		public function add_newadress(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			}
			else if(!isset($postData['phone_no']) || empty($postData['phone_no'])){
				$err = 1;
				$msg = 'Phone Number is Required';
			}
			else if(!isset($postData['house_no']) || empty($postData['house_no'])){
				$err = 1;
				$msg = 'House Number is Required';
			}
			else if(!isset($postData['area']) || empty($postData['area'])){
				$err = 1;
				$msg = 'Area is Required';
			}
			else if(!isset($postData['city']) || empty($postData['city'])){
				$err = 1;
				$msg = 'City is Required';
			}
			else if(!isset($postData['name']) || empty($postData['name'])){
				$err = 1;
				$msg = 'Name is Required';
			}
			else if(!isset($postData['country']) || empty($postData['country'])){
				$err = 1;
				$msg = 'Country is Required';
			}
			else if(!isset($postData['phonecode']) || empty($postData['phonecode'])){
				$err = 1;
				$msg = 'Phonecode  is Required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->add_newadress($postData);
			echo json_encode($respArr); exit;
		}
//Get Delivery Address
		public function get_deliveryadress(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_deliveryadress($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Get Delivery Address By Id
		public function get_deliveryadressbyid(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['adress_id']) || empty($postData['adress_id'])){
				$respArr['message'] = 'Address Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_deliveryadressbyid($postData['adress_id']);
			echo json_encode($respArr); exit;
		}
//Edit Address
		public function editaddress(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			}
			else if(!isset($postData['adress_id']) || empty($postData['adress_id'])){
				$err = 1;
				$msg = 'Address Id is Required';
			}
			else if(!isset($postData['phone_no']) || empty($postData['phone_no'])){
				$err = 1;
				$msg = 'Phone Number is Required';
			}
			else if(!isset($postData['house_no']) || empty($postData['house_no'])){
				$err = 1;
				$msg = 'House Number is Required';
			}
			else if(!isset($postData['area']) || empty($postData['area'])){
				$err = 1;
				$msg = 'Area is Required';
			}
			else if(!isset($postData['city']) || empty($postData['city'])){
				$err = 1;
				$msg = 'City is Required';
			}
			else if(!isset($postData['name']) || empty($postData['name'])){
				$err = 1;
				$msg = 'Name is Required';
			}
			else if(!isset($postData['country']) || empty($postData['country'])){
				$err = 1;
				$msg = 'Country is Required';
			}
			else if(!isset($postData['district']) || empty($postData['district'])){
				$err = 1;
				$msg = 'District is Required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->editaddress($postData);
			echo json_encode($respArr); exit;
		}
//Request Product
		public function request_product(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			$err = 0;
			$msg = '';
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$err = 1;
				$msg = 'User Id is Required';
			}
			else if(!isset($postData['prod_id']) || empty($postData['prod_id'])){
				$err = 1;
				$msg = 'Product Id is Required';
			}
			else if(!isset($postData['car_id']) || empty($postData['car_id'])){
				$err = 1;
				$msg = 'Car Id is Required';
			}
			else if(!isset($postData['delivery_adressId']) || empty($postData['delivery_adressId'])){
				$err = 1;
				$msg = 'Delivery Address Id is Required';
			}
			if($err == 1){
				$respArr['message'] = $msg;
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->request_product($postData);
			echo json_encode($respArr); exit;
		}
//Get Request Details
		public function get_requestedetails(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_requestedetails($postData['user_id']);
			echo json_encode($respArr); exit;
		}
//Get Product Request Details By Id
		public function get_productrequestdetailsbyId(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['request_id']) || empty($postData['request_id'])){
				$respArr['message'] = 'Request Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_productrequestdetailsbyId($postData['request_id']);
			echo json_encode($respArr); exit;
		}
//Get Request Accepted Shop List
		public function get_requestacceptedshoplist(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['request_id']) || empty($postData['request_id'])){
				$respArr['message'] = 'Request Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_requestacceptedshoplist($postData['request_id']);
			echo json_encode($respArr); exit;
		}
//Get Shop Details
		public function get_shopdetails(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['req_id']) || empty($postData['req_id'])){
				$respArr['message'] = 'Shop Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_shopdetails($postData['request_id']);
			echo json_encode($respArr); exit;
		}
//Purchase Product
		public function purchaseproduct(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['response_id']) || empty($postData['response_id'])){
				$respArr['message'] = 'Response Id is Required';
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['req_id']) || empty($postData['req_id'])){
				$respArr['message'] = 'Request Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->purchaseproduct($postData);
			echo json_encode($respArr); exit;
		}
//Get Booked Details
		public function get_bookedpartdetail(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['booking_id']) || empty($postData['booking_id'])){
				$respArr['message'] = 'Booking Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_bookedpartdetail($postData['booking_id']);
			echo json_encode($respArr); exit;
		}
//Get Request Accepted Garage
		public function get_requestacceptedgarage(){
			$postData = $_GET;
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['request_id']) || empty($postData['request_id'])){
				$respArr['message'] = 'Request Id is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->get_requestacceptedgarage($postData['request_id']);
			echo json_encode($respArr); exit;
		}

		public function all_productList(){
			header('Content-type: application/json');
			$respArr = $this->Webservice_model->all_productList();
			echo json_encode($respArr); exit;
		}

		public function changePassword(){
			$post = file_get_contents("php://input");
			$postData = json_decode($post, true);
			$respArr = array('status'=>'error','message'=>'Something went wrong.');
			if(empty($postData)){
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['user_id']) || empty($postData['user_id'])){
				$respArr['message'] = 'User Id is Required';
				echo json_encode($respArr);exit;
			}
			if(!isset($postData['password']) || empty($postData['password'])){
				$respArr['message'] = 'Password is Required';
				echo json_encode($respArr);exit;
			}
			$respArr = $this->Webservice_model->changePassword($postData);
			echo json_encode($respArr); exit;
		}

	}
?>
