<?php

namespace App\Modules\HtlCampSchedule\Application\Order;

use DateTime;

class MapSchedule
{

    private $schedule;

    public function __construct(
        private array $scheduleArray
    ) {
        $this->schedule = (object)[];
        foreach ($scheduleArray as $day) {
            $this->schedule->{$day->date} = $day;
        }
    }

    public function append(array $scheduleArray)
    {
        foreach ($scheduleArray as $day) {
            $this->schedule->{$day->date} = $day;
        }
    }

    public function getAvailability(string $date)
    {
        return $this->schedule->{$date}->availability;
    }

    public function getDateFromKey(string $date)
    {
        return $this->schedule->{$date}->availability;
    }

    public function getDate(DateTime $date)
    {
        $format = $date->format('Y-m-d');
        if (!isset($this->schedule->{$format})) {
            return null;
        }
        return $this->schedule->{$format};
    }
}
