<?php

namespace App\Http\Controllers;
use App\Models\Booking;
use App\Models\GlobalOption;

use Illuminate\Http\Request;

class UtilityController extends Controller
{
    public function available_seats(Request $request)
    {
       $booking_date = $request->input('booking_date');
        $timeslot = $request->input('timeslot');
        $booked_seats = Booking::where('booking_date',$booking_date)->where('timeslot',$timeslot)->where('status', 'reserved')->sum('seats');
        $remaining_seats = 25 - $booked_seats; //todo: make total seats dynamic
        return response()->json($remaining_seats);
    }

    public function seat_price()
    {
         $price = GlobalOption::get()->first()->seat_price;
         return response()->json($price);
    }

    public function reloadCaptcha()
    {
        return response()->json(['captcha'=> captcha_img()]);
    }
}
