<?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 ReportsController extends Controller
{ 
    public function __construct(Request $request) {
        if($request->has('debug') && $request->input('debug') == true) {
            $this->debug = true;			
        }
    }
	
	public function getReports(Request $request)
    {      
		$result = array();
		//include_once "/home/steelmin/public_html/api/storage/v2019/reports_pre.php";
		$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_reports_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/web_reports_pre.php";
			}
		} else {
		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/reports_pre.php";
				$code = 2013;
				$message = "User not found.";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/reports_post.php";
				$code = 1001;
				$message = "Success";
			}
        }else{
			include_once "/home/steelmin/public_html/api/storage/v2019/reports_pre.php";
			$code = 1001;
			$message = "Success";
		}
	}	
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    }  
	
	public function getReportCount(Request $request){
		$result = array();
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			$result = array(
				"upcoming" => 57,
				"archived" => 365
			 );
		} elseif($resourceType=='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/reports_pre.php";
					$code = 2013;
					$message = "User not found.";
				}else{
					include_once "/home/steelmin/public_html/api/storage/v2019/reports_post.php";
					$code = 1001;
					$message = "Success";
				}
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/reports_pre.php";
				$code = 1001;
				$message = "Success";
			} */
		}else{
			$code = 2001;
			$message = "invalid input";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}
	
}
