<?php
namespace App\Http\Controllers;

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

class UnitTestController extends Controller
{
	public function getPriceCategory()
	{
		$category = array();

		$category[] = array(
			"name"		=>	"IRON ORE",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"COAL",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"SCRAP",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"SHIP BREAKING",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"SEMI FINISHED",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"FINISH STEEL",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"FERRO ALLOY",
			"DOM"		=>	array(),
			"E_I"		=>	array()
		);

		$category[] = array(
			"name"		=>	"LOGISTICS",
			"DOM"		=>	array(),
			"E_I"		=>	array(
				"LOGISTICS"	=>	[
					"Iron Ore",
					"Coal"
				]
			)
		);

		$results['category'] = $category;

		return new JsonResponse( array("status#"=>"1", "data#"=> $results)) ;
	}

	public function getPrices(Request $request)
	{
		include($_ENV['COMMON_ROOT_PATH'].'/mappNew.php');

		$filter = array();
		$sub_category = '';
		if($request->has('category')) {
            $sub_category = $request->input('category');
            $filter['sub_category'] = $sub_category;
        }

        $results = getPricesForApp(2, $filter);
        $data = array();
        if($results) {
        	foreach($results as $result) {
        		$result['category'] = $sub_category;
        		$data[] = $result;
        	}
        }

        return new JsonResponse( array("status#"=>"1", "data#"=> $data)) ;
	}

	public function getNewsCategory()
	{
		$result = array();

		$result[] = array(
			"cat_id"	=>	1,
			"cat_name"	=>	"Iron Ore",
			"sub_cat"	=>	array(),
			"regions"	=>	[
				array(
					"India"		=>	"India",
					"China"		=>	"China",
					"Pakistan"	=>	"Pakistan",
					"Japan"		=>	"Japan"
				)
			]
		);

		$result[] = array(
			"cat_id"	=>	2,
			"cat_name"	=>	"Coal",
			"sub_cat"	=>	array(),
			"regions"	=>	[
				array(
					"Pakistan"	=>	"Pakistan",
					"Japan"		=>	"Japan",
					"China"			=>	"China",
					"Bangladesh"	=>	"Bangladesh"
				)
			]
		);

		$result[] = array(
			"cat_id"	=>	3,
			"cat_name"	=>	"Scrap",
			"sub_cat"	=>	array(),
			"regions"	=>	[
				array(
					"Korea"			=>	"Korea",
					"Bangladesh"	=>	"Bangladesh"
				)
			]
		);

		$result[] = array(
			"cat_id"	=>	4,
			"cat_name"	=>	"Ship Breaking",
			"sub_cat"	=>	array(),
			"regions"	=>	[
				array(
					"China"			=>	"China",
					"Bangladesh"	=>	"Bangladesh"
				)
			]
		);

		return new JsonResponse( array("status#"=>"1", "data#"=> $result ) ) ;
	}

	public function getNews(Request $request)
	{
		include_once "/home/steelmin/public_html/inc/config1.php";	
    	include('/home/steelmin/public_html/hf.php');

		$userAccess = -1;
        $web_domain = 'steelmint.com';

        $filter = array();

		if($request->has('category')) {
            $sub_category = $request->input('category');
            $filter['sub_category'] = $sub_category;
        }

        $filter['start'] = 0;
		$filter['limit'] = 10;

        $results = get_news_details($filter, $web_domain, 0, $userAccess);

        include_once "/home/steelmin/public_html/inc/desconfig.php";	
        return new JsonResponse(array("status#" => "1" , "data#" => $results));
	}
}