<?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\ValueObject;

use BookiFlex\Core\Util\DateTimeUtils;

defined( 'ABSPATH' ) || exit;

class StayPeriod
{
    public function __construct(
        private readonly \DateTimeImmutable $checkInDate,
        private readonly \DateTimeImmutable $checkOutDate
    ) {
        if ($checkInDate >= $checkOutDate) {
            throw new \InvalidArgumentException('Check-out date must be after check-in date');
        }
    }

    public function getCheckInDate(): \DateTimeImmutable { return $this->checkInDate; }
    public function getCheckOutDate(): \DateTimeImmutable { return $this->checkOutDate; }
    public function getLengthOfStay(): int
    {
        return DateTimeUtils::lengthOfStay($this->checkInDate, $this->checkOutDate);
    }

    public function overlaps(StayPeriod $other): bool
    {
        return $this->checkInDate < $other->checkOutDate && $this->checkOutDate > $other->checkInDate;
    }
}
