<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Core\Service\DateUnit;

use BookiFlex\Core\Repository\DateUnitRepository;

defined( 'ABSPATH' ) || exit;

/**
 * Return MIN and MAX date for set DateUnits by RatePlan and AccommodationType.
 * If no DateUnits found, return ['min' => null, 'max' => null]
 */
class GetMinMaxDates
{
    private DateUnitRepository $dateUnitRepository;

    public function __construct(DateUnitRepository $dateUnitRepository)
    {
        $this->dateUnitRepository = $dateUnitRepository;
    }

    /**
     * @param int $ratePlanId
     * @param int $accommodationTypeId
     * @return array ['min' => 'Y-m-d'|null, 'max' => 'Y-m-d'|null]
     */
    public function getMinMaxDates(int $ratePlanId, int $accommodationTypeId): array
    {
        $result = $this->dateUnitRepository->findMinMaxDateBy($ratePlanId, $accommodationTypeId);

		if ($result !== null) {
			return $result;
		}

		return ['min' => null, 'max' => null];
    }
}
