<?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
 */

namespace E4J\VikRestaurants\Room\Closure;

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

use E4J\VikRestaurants\Collection\Item;

/**
 * Interface used to provide a dataset of room closures into a collection.
 * 
 * @since 1.10
 */
class RoomClosure extends Item
{
    /**
     * Returns a date time instance when the closure starts.
     * 
     * @return  \DateTime
     */
    public function getStartDate()
    {
        return \JFactory::getDate(date('Y-m-d H:i:s', $this->start_ts));
    }

    /**
     * Returns a date time instance when the closure ends.
     * 
     * @return  \DateTime
     */
    public function getEndDate()
    {
        return \JFactory::getDate(date('Y-m-d H:i:s', $this->end_ts));
    }

    /**
     * Returns a date time instance when the closure should stop.
     * 
     * @return  \DateTime
     */
    public function getStopDate()
    {
        return $this->stop > 0 ? \JFactory::getDate(date('Y-m-d H:i:s', $this->stop)) : null;
    }

    /**
     * Returns the recurrence instance matching the configured repeat property.
     * 
     * @return  Recurrence
     */
    public function getRecurrence()
    {
        switch (strtolower((string) $this->repeat))
        {
            case 'daily':
                return new \E4J\VikRestaurants\Recurrence\Types\DailyRecurrence($this->getStartDate(), $this->getEndDate(), $this->getStopDate());

            case 'weekly':
                return new \E4J\VikRestaurants\Recurrence\Types\WeeklyRecurrence($this->getStartDate(), $this->getEndDate(), $this->getStopDate());

            case 'monthly':
                return new \E4J\VikRestaurants\Recurrence\Types\MonthlyRecurrence($this->getStartDate(), $this->getEndDate(), $this->getStopDate());

            case 'yearly':
                return new \E4J\VikRestaurants\Recurrence\Types\YearlyRecurrence($this->getStartDate(), $this->getEndDate(), $this->getStopDate());

            default:
                return new \E4J\VikRestaurants\Recurrence\Types\NullRecurrence($this->getStartDate(), $this->getEndDate(), $this->getStopDate());
        }
    }
}
