<?php
/** 
 * @package     VikRestaurants
 * @subpackage  core
 * @author      E4J s.r.l.
 * @copyright   Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @link        https://vikwp.com
 */

// No direct access
defined('ABSPATH') or die('No script kiddies please!');

/**
 * VikRestaurants room closure model.
 *
 * @since 1.9
 */
class VikRestaurantsModelRoomclosure extends JModelVRE
{
    /**
     * Returns all the closures matching the specified room ID and check-in.
     * 
     * @param   int    $roomId   The ID of the room.
     * @param   mixed  $checkin  Either a timestamp, a date string or a date time instance.
     * 
     * @return  ClosuresCollection
     * 
     * @since   1.10
     */
    public function getRoomClosures(int $roomId, $checkin)
    {
        // take all the closures that match the provided room ID and check-in
        return \E4J\VikRestaurants\Room\Closure\ClosuresCollection::getInstance()
            ->filter(new \E4J\VikRestaurants\Room\Closure\Filters\RoomFilter($roomId))
            ->filter(new \E4J\VikRestaurants\Room\Closure\Filters\DateFilter($checkin));
    }

    /**
     * Checks whether the specified room is open on a given check-in date time.
     * 
     * @param   int    $roomId   The ID of the room.
     * @param   mixed  $checkin  Either a timestamp, a date string or a date time instance.
     * 
     * @return  bool   True if open, false otherwise.
     * 
     * @since   1.10
     */
    public function isRoomOpen(int $roomId, $checkin)
    {
        // Take all the closures that match the provided room ID and check-in.
        // The room will result open in case we don't have any matching records.
        return $this->getRoomClosures($roomId, $checkin)->count() == 0;
    }

    /**
     * Checks whether the specified room is closed on a given check-in date time.
     * 
     * @param   int    $roomId   The ID of the room.
     * @param   mixed  $checkin  Either a timestamp, a date string or a date time instance.
     * 
     * @return  bool   True if closed, false otherwise.
     * 
     * @since   1.10
     */
    public function isRoomClosed(int $roomId, $checkin)
    {
        // Take all the closures that match the provided room ID and check-in.
        // The room will result closed in case we have at least a matching record.
        return (bool) $this->getRoomClosures($roomId, $checkin)->count();
    }
}
