<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\CancelBooking;
use App\Branch;

class CancelBookingController extends Controller
{
    private $cancel_booking;

    public function __construct()
    {
        $this->cancel_booking = new CancelBooking;

        $this->branch = new Branch;
    }

    public function getAllCancelBookings(Request $request)
    {
        $condition_in = ['Cancel'];



       $data = [
        'cancelbooking_list'  =>  $this->cancel_booking->getAllCancelBookings(),
       ];

       return view('booking.view_cancel_booking',[
        
            'view_booking'  =>  view('components.booking.table_cancelbooking',$data)->render(),
            'branch'        =>  $this->branch->getBranchList(),
        ]);
    }

    public function removeCancelBooking(Request $request)
    {
        try{

            $id = decrypt($request->id);

            $is_verify = $this->cancel_booking->isVerifyCancelBooking($id);

            if($is_verify['status'] === true)
            {
                $cancel_booking = $this->cancel_booking->removeCancelBooking($id);

                if(isset($cancel_booking->id))
                {
                    // SET ERROR MESSAGE APPROVE BOOKING
                    parent::setLogMessage('Cancel booking has removed against the file no. '.$cancel_booking->booking->file_number);

                    parent::successMessage('Booking Cancel has removed succssfully.',parent::getLogMessage());
                  // END
                }
            } 
            else
            {
                parent::errorMessage($is_verify['message']);
            }
        }
        catch(DecryptException $e)
        {

        }

        return redirect()->back();
    }
}
