<?php
namespace App\Http\Controllers\v2019;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\JsonResponse;

class PricesController extends Controller
{ 
    public function __construct(Request $request) {
        if($request->has('debug') && $request->input('debug') == true) {
            $this->debug = true;			
        }
    }
	
	public function getPrices(Request $request)
    {      
		$result = array();
		$source = strtolower($request->input('source'));
		
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/web/web_prices_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/web_prices_pre.php";
			}
		}else{///app
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			   // $auth = new authentication();
				$token = $request->input('accessToken');
				if(empty($token)){
					
					include_once "/home/steelmin/public_html/api/storage/v2019/prices_pre.php";
					
					$code = 2013;
					$message = "User not found.";
				}else{
					if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/prices_home_post.php";
					else
						include_once "/home/steelmin/public_html/api/storage/v2019/prices_post.php"; 
					$code = 1001;
					$message = "Success";
				}
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/prices_pre.php";
					
				$code = 1001;
				$message = "Success";
			}
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result, "defaultItemsCount"=> 5));
    }  
	
    public function getPriceDetails(Request $request){
		$result = array();
		$source = strtolower($request->input('source'));
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
            $token = $request->input('accessToken');
			if(empty($token)){
			    include_once "/home/steelmin/public_html/api/storage/v2019/web/web_prices_details_pre.php"; 		
				$code = 2013;
				$message = "User not found.";
			}else{
				$code = 1001;
				$message = "Success";
			}
        }else{
			include_once "/home/steelmin/public_html/api/storage/v2019/web/web_prices_details_pre.php"; 
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}

	public function getPricesGraph(Request $request)
    {      
	   $result = array();
	   include_once "/home/steelmin/public_html/api/storage/v2019/prices_graph_post.php";
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found.";
			}else{
				///full data///
				$code = 1001;
				$message = "Success";
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	
	public function getCostIndex(Request $request)
    {      
	   $result = array();
	   include_once "/home/steelmin/public_html/api/storage/v2019/costindex_pre.php";
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found.";
			}else{
				///full data///
				$code = 1001;
				$message = "Success";
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	
	public function getPortfolioListItems(Request $request)
    {      
	    $result = array();
	    include_once "/home/steelmin/public_html/api/storage/v2019/portfolio_post.php";
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found.";
			}else{
				///full data///
				$code = 1001;
				$message = "Success";
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	///Comparison/ Display Saved comparison
	public function compare(Request $request)
    {      
	    $result = array();
	   
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found."; 
			}else{
				 //include_once "/home/steelmin/public_html/api/storage/v2019/saved_comparison_display_listing.php";
				 include_once "/home/steelmin/public_html/api/storage/v2019/save_compare.php";
				///full data///
				$code = 1001;
				$message = "Success";
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	
	///
	public function compareSave(Request $request)
    {      
	    $result = array();
	    //include_once "/home/steelmin/public_html/api/storage/v2019/save_compare.php";
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found."; 
			}else{
				
				///full data///
				$code = 1001;
				$message = "Successfully Saved";
				$result['comparisonId'] = 11;
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	
	//Compare - Mapping data
	public function compareFilterList(Request $request)
    {      
	    $result = array();
		$source = strtolower($request->input('source'));
		
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/web/compare_mapping_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/compare_mapping_post.php";
			}
		}else{
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			// $auth = new authentication();
			$token = $request->input('accessToken');
			if(empty($token)){
					///not loggedin/visitor///
					$code = 2013;
					$message = "User not found."; 
				}else{
					include_once "/home/steelmin/public_html/api/storage/v2019/compare_mapping_post.php";
					///full data///
					$code = 1001;
					$message = "Success";
				}
			}else{
				///not loggedin/visitor///
				
				$code = 1001;
				$message = "Success";
			}
	}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    } 
	
	//Saved comparison listing
	public function getCompareSavedList(Request $request)
    {      
	    $result = array();
	   
		if ($request->has('accessToken') && $request->input('accessToken')!='') {
           // $auth = new authentication();
           $token = $request->input('accessToken');
           if(empty($token)){
				///not loggedin/visitor///
				$code = 2013;
				$message = "User not found."; 
			}else{
				 include_once "/home/steelmin/public_html/api/storage/v2019/saved_comparison_listing.php";
				///full data///
				$code = 1001;
				$message = "Success";
			}
        }else{
			///not loggedin/visitor///
			
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}
	
	public function getHistoricalData(Request $request){
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
			 
		    $code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/web/history_prices_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/history_prices_pre.php";
			}
			return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result, "defaultItemsCount"=> 5));
	}
	

}
