<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Booking;
use App\Models\Client;
use App\Models\SalesPoc;
use App\Models\OpsPoc;
use App\Models\ServicesType;
use App\Models\HotelVendor;
use App\Models\LandVendor;
use App\DataTables\BookingDataTable;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Response;

class BookingController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index(BookingDataTable $dataTable)
    {
        return $dataTable->render('booking.index');
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        $clients = Client::all();
        $salespocs = SalesPoc::all();
        $opspoc = OpsPoc::all();
        $servietypes = ServicesType::all();
        $hotelvendors = HotelVendor::all();
        $landvendors = LandVendor::all();
        return view('booking.create', compact('clients','salespocs','opspoc','servietypes','hotelvendors','landvendors'));
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        // dd($request->all());
        $input = $request->all();
        $create_inquiry = new Booking($input);
        $create_inquiry->save();
        return redirect('booking')->with('success', 'booking Created successfully');
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        $bookings = Booking::where('id','=',$id)->get();
        $clients = Client::all();
        $salespocs = SalesPoc::all();
        $opspoc = OpsPoc::all();
        $servietypes = ServicesType::all();
        $hotelvendors = HotelVendor::all();
        $landvendors = LandVendor::all();
        return view('booking.show', compact('bookings','clients','salespocs','opspoc','servietypes','hotelvendors','landvendors'));
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        $bookings = Booking::where('id','=',$id)->get();
        $clients = Client::all();
        $salespocs = SalesPoc::all();
        $opspoc = OpsPoc::all();
        $servietypes = ServicesType::all();
        $hotelvendors = HotelVendor::all();
        $landvendors = LandVendor::all();
        return view('booking.edit', compact('bookings','clients','salespocs','opspoc','servietypes','hotelvendors','landvendors'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request)
    {
        $input = $request->all();
        $booking_update = Booking::find($request->id);
        $booking_update->update($input);
        return redirect('booking')->with('success', 'booking Updated Successfully');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Request $request)
    {
        $booking_delete = Booking::find($request->id);
        $booking_delete->delete();
        Session::flash('success', __('Booking Data Delete Succesfully'));
        $data            = array();
        return Response::json([
            'success' => true,
            'data'    => $data,
        ]);
    }
}
