<?php

namespace App\Classes\Modules\Bookings\Services;


use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\General\Eloquent\AbstractGetRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Booking;
use Illuminate\Database\Eloquent\Collection;

class GetBookings extends AbstractGetRecord
{

    /** @var Booking */
    private $repository;

    /**
     * FetchesUser constructor.
     * @param Booking $repository
     */
    public function __construct(Booking $repository)
    {
        $this->repository = $repository;
    }


    /**
     * @return Builder
     */
    public function getRepository(): Builder
    {
        return $this->repository->newQuery();
    }

    /**
     * @param Builder $query
     * @return Collection
     * @throws ResourceNotFoundException
     */
    public function getResults(Builder $query):Collection
    {
        if (!$query->exists()) {
            throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
        }

        return $query->get();
    }


}