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

use App\Http\Controllers\Controller;

use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

use App\Http\Helpers\ResponseBuilder;
use App\Http\Helpers\ParamsValidator;
use App\Http\History\HistoryData;
use App\Http\History\HistoryTables;
use Intervention\Image\ImageManagerStatic as Image;

class c_Tour_Upgrade_Type extends Controller
{
	private $oDomain;
	/** @var HistoryData */
	private $history;

	public function __construct()
	{
		$this->oDomain = "Tour Upgrade Type";
		$this->history = new HistoryData (HistoryTables::tour_upgrade_type);
	}

	public function Insert(Request $Request){
		$oResponse  = array();
		$oValParams = array(    
								'TourUpgradeType_Description'		=> 'string',
								'TourUpgradeType_Multiple'			=> 'required|int',
								'TourUpgradeType_VisibleEndorser'	=> 'required|int',
								'TourUpgradeType_VisibleUser'		=> 'required|int',
								'TourUpgradeType_Status'			=> 'required|int',
								'Id_Tour'							=> 'required|int',
								'Id_TypeUpgrade'					=> 'required|int'
							);


		// VALIDANDO DATOS
		$oResponse = ParamsValidator::Validate_Request($Request,$oValParams,$this->oDomain);
		
		//  INGRESANDO DATOS
		if ($oResponse["Response_Code"] == 200) {			
			$oParam = array(    $Request->input("TourUpgradeType_Description"),
								$Request->input("TourUpgradeType_Multiple"),
								$Request->input("TourUpgradeType_VisibleEndorser"),
								$Request->input("TourUpgradeType_VisibleUser"),
								$Request->input("TourUpgradeType_Status"),
								$Request->input("Id_Tour"),
								$Request->input("Id_TypeUpgrade")
							);
			$oData = DB::select('call sp_tour_upgrade_type_insert(?,?,?,?,?,?,?)',$oParam);

			//  RESPONSE
			if ($oData[0]->Response_Success == 1) {
				//region HISTORY EXEC
				$this->history->insertBasic ($Request);
				//endregion
			} else {
				
			}
			
			$oResponse["Response_Status"]			= $oData[0]->Response_Status;
			$oResponse["Response_Code"]				= $oData[0]->Response_Code;
			$oResponse["Response_Domain"]			= $this->oDomain;
			$oResponse["Response_Message"]			= $oData[0]->Response_Message;
			$oResponse["Response_Data"]				= null;
			$oResponse["Response_Error_Message"]	= $oData[0]->Response_Message;
			$oResponse["Response_Error_Reason"]		= $oData[0]->Response_Reason;
		}

		return ResponseBuilder::Response($oResponse);
		
	}
	public function Update(Request $Request){
		$oResponse  = array();
		$oValParams = array(    'Id_TourUpgradeType'				=> 'required|int',
								'TourUpgradeType_Description'		=> 'string',
								'TourUpgradeType_Order'				=> 'required|int',
								'TourUpgradeType_Multiple'			=> 'required|int',
								'TourUpgradeType_VisibleEndorser'	=> 'required|int',
								'TourUpgradeType_VisibleUser'		=> 'required|int',
								'TourUpgradeType_Status'			=> 'required|int',
								'Id_Tour'							=> 'required|int',
								'Id_TypeUpgrade'					=> 'required|int'
							);


		// VALIDANDO DATOS
		$oResponse = ParamsValidator::Validate_Request($Request,$oValParams,$this->oDomain);
		
		//  INGRESANDO DATOS
		if ($oResponse["Response_Code"] == 200) {
			
			//region HISTORY VARIABLES
			$this->history->obtainOld($Request->input('Id_TourUpgradeType'));
			//endregion
			$oParam = array(    $Request->input("Id_TourUpgradeType"),
								$Request->input("TourUpgradeType_Description"),
								$Request->input("TourUpgradeType_Order"),
								$Request->input("TourUpgradeType_Multiple"),
								$Request->input("TourUpgradeType_VisibleEndorser"),
								$Request->input("TourUpgradeType_VisibleUser"),
								$Request->input("TourUpgradeType_Status"),
								$Request->input("Id_Tour"),
								$Request->input("Id_TypeUpgrade")
							);
			$oData = DB::select('call sp_tour_upgrade_type_update(?,?,?,?,?,?,?,?,?)',$oParam);

			//  RESPONSE
			if ($oData[0]->Response_Success == 1) {
				//region HISTORY EXEC
				$this->history->updateBasic ( $Request->input("Id_TourUpgradeType"), $Request );
				//endregion
			} else {
				
			}
			
			$oResponse["Response_Status"]			= $oData[0]->Response_Status;
			$oResponse["Response_Code"]				= $oData[0]->Response_Code;
			$oResponse["Response_Domain"]			= $this->oDomain;
			$oResponse["Response_Message"]			= $oData[0]->Response_Message;
			$oResponse["Response_Data"]				= null;
			$oResponse["Response_Error_Message"]	= $oData[0]->Response_Message;
			$oResponse["Response_Error_Reason"]		= $oData[0]->Response_Reason;
		}

		return ResponseBuilder::Response($oResponse);

	}
	public function Delete(Request $Request, $Id){
		$oResponse  = array();

		// VALIDANDO DATOS
		$oResponse = ParamsValidator::Validate_Id($Id,$this->oDomain);
		
		//  INGRESANDO DATOS
		if ($oResponse["Response_Code"] == 200) {
			
			//region HISTORY
			$this->history->obtainOld($Id);
			//endregion

			$oParam = array( $Id );
			$oData 	= DB::select('call sp_tour_upgrade_type_delete(?)',$oParam);
			
			//  RESPONSE
			if ($oData[0]->Response_Success == 1) {
				//region HISTORY EXEC
				$this->history->deleteBasic ($Id, $Request);
				//endregion
			} else {
				
			}
			
			$oResponse["Response_Status"]			= $oData[0]->Response_Status;
			$oResponse["Response_Code"]				= $oData[0]->Response_Code;
			$oResponse["Response_Domain"]			= $this->oDomain;
			$oResponse["Response_Message"]			= $oData[0]->Response_Message;
			$oResponse["Response_Data"]				= null;
			$oResponse["Response_Error_Message"]	= $oData[0]->Response_Message;
			$oResponse["Response_Error_Reason"]		= $oData[0]->Response_Reason;
		}

		return ResponseBuilder::Response($oResponse);
	}
	public function Index(Request $Request, $Id){
		$oResponse  = array();

		// VALIDANDO DATOS
		$oResponse = ParamsValidator::Validate_Id($Id,$this->oDomain);
		
		//  INGRESANDO DATOS
		if ($oResponse["Response_Code"] == 200) {		
			$oParam = array( $Id );
			$oData 	= DB::select('call sp_tour_upgrade_type_index(?)',$oParam);
			
			$oResponse["Response_Status"]			= 200;
			$oResponse["Response_Code"]				= 200;
			$oResponse["Response_Domain"]			= $this->oDomain;
			$oResponse["Response_Message"]			= $this->oDomain."Index";
			$oResponse["Response_Data"]				= $oData;
			$oResponse["Response_Error_Message"]	= "";
			$oResponse["Response_Error_Reason"]		= "";
		}

		return ResponseBuilder::Response($oResponse);
	}
	public function List(Request $Request, $Id_Tour, $Id){
		$oResponse  = array();
		
		$oResponse = ParamsValidator::Validate_Id($Id_Tour,$this->oDomain);
		
		if ($oResponse["Response_Code"] == 200) {
			$oResponse = ParamsValidator::Validate_Action($Id,$this->oDomain);

			if ($oResponse["Response_Code"] == 200) {
				$oParam = array( $Id, $Id_Tour );
				$oData  = DB::select('call sp_tour_upgrade_type_list(?,?)',$oParam);

				$oResponse["Response_Status"]			= 200;
				$oResponse["Response_Code"]				= 200;
				$oResponse["Response_Domain"]			= $this->oDomain;
				$oResponse["Response_Message"]			= $this->oDomain." list ".$Id;
				$oResponse["Response_Data"]				= $oData;
				$oResponse["Response_Error_Message"]	= "";
				$oResponse["Response_Error_Reason"]		= "";
			}
		}
		return ResponseBuilder::Response($oResponse);
	}

	
}