<?php

namespace App\Http\Controllers;

use App\Models\Booking;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Carbon\Carbon;
use App\Models\User;
use Illuminate\Support\Facades\DB;

class OComplimentaryBookingsController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        
        $this->booking = new Booking;
    }
    
    /**
     * Show my booking
     *
     * @return array
     */
    public function index(Request $request, $view = 'o_complimentarybookings.index', $extra = [])
    {
        // get prifex from eventmie config
        $path = false;
        if(!empty(config('eventmie.route.prefix')))
            $path = config('eventmie.route.prefix');
        
        $path = !empty($path) ? $path.'/dashboard/complimentary-bookings' : '/dashboard/complimentary-bookings';

        // show organiser_bookings
        return view($view, compact('path', 'extra'));
    }

    
    /**
     * Show organiser complimentary bookings
     *
     * @return array
     */
    public function organiser_complimentary_bookings(Request $request)
    {
        $params     = [
            'organiser_id'  => Auth::id(),
            'event_id'      => $request->event_id,
            'length'        => $request->length,
        ];

        $bookings = $this->booking->get_organiser_complimentary_bookings($params);

        return response([
            'bookings'  => $bookings->jsonSerialize(),
            'currency'  => setting('regional.currency_default'),
        ], Response::HTTP_OK);
    }

}
