<?php
namespace Booktics\Appointment\Schedule;

use JsonSerializable;

/**
 * Timeslot class
 */
class Time_Slot implements JsonSerializable {
    /**
     * Store start time
     *
     * @var string
     */
    public $start;

    /**
     * Store end time
     *
     * @var string
     */
    public $end;

    /**
     * Store time slot status
     *
     * @var bool
     */
    public $is_available;

    /**
     * Store maximum capacity
     *
     * @var int
     */
    public $max_capacity;

    /**
     * Store booked count
     *
     * @var int
     */
    public $booked_count;

    /**
     * Store available spots
     *
     * @var int
     */
    public $available_spots;

    /**
     * Constructor timeslot class
     *
     * @param   string  $start        Start time for a time slot
     * @param   string  $end          End time for a time slot
     * @param   bool    $is_available  Status for time slot
     * @param   true
     *
     * @return  void
     */
    public function __construct( string $start, string $end, bool $is_available = true, int $max_capacity = 1, int $available_spots = 1, int $booked_count = 0 ) {
        $this->start        = $start;
        $this->end          = $end;
        $this->is_available = $is_available;
        $this->max_capacity = $max_capacity;
        $this->booked_count = $booked_count;
        $this->available_spots = $available_spots;
    }

    /**
     * Get time slot data as an array
     *
     * @return  array   Timeslot data
     */
    public function to_array(): array {
        return [
            'start'        => $this->start,
            'end'          => $this->end,
            'is_available' => $this->is_available,
            'max_capacity' => $this->max_capacity,
            'booked_count' => $this->booked_count,
            'available_spots' => $this->available_spots,
        ];
    }

    /**
     * Specify data which should be serialized to JSON.
     *
     * @return array
     */
    public function jsonSerialize(): array {
        return $this->to_array();
    }
}
