<?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\Model\Reservation;

use BookiFlex\Core\Model\AbstractStatus;

defined( 'ABSPATH' ) || exit;

/**
 * Describes reservation status.
 *
 * CART - status is used when reservation is in the creation process.
 * OVERDUE - status is used when reservation is not paid in time. Depends on the hotel policy, reservation can be cancelled.
 * WAITING_CONFIRMATION - status is used when reservation is created and waiting for confirmation (Need confirmation) by the hotel.
 * WAITING_PAYMENT - status is used when reservation is confirmed and waiting for payment.
 * CONFIRMED - status is used when reservation is confirmed manually by the hotel OR automatically by the system after payment (if this hotel rules was set).
 * CANCELLED
 *
 * IN_HOUSE
 * NO_SHOW
 * COMPLETED
 *
 * Transitions:
 * cart -> waiting_payment -> waiting_confirmation -> confirmed -> cancelled
 * cart -> waiting_payment -> waiting_confirmation -> confirmed
 * cart -> waiting_payment -> overdue -> cancelled
 * cart -> waiting_payment -> cancelled
 * cart -> waiting_confirmation -> confirmed -> cancelled
 * cart -> waiting_confirmation -> confirmed -> in house -> completed
 * cart -> waiting_confirmation -> confirmed -> no show
 * cart -> waiting_confirmation -> confirmed
 * cart -> waiting_confirmation -> cancelled
 */
class ReservationStatus extends AbstractStatus
{
    public const STATUS_CART                 = 'CART';
    public const STATUS_WAITING_CONFIRMATION = 'WAITING_CONFIRMATION';
    public const STATUS_WAITING_PAYMENT      = 'WAITING_PAYMENT';
    public const STATUS_OVERDUE              = 'OVERDUE';
    public const STATUS_CONFIRMED            = 'CONFIRMED';
    public const STATUS_CANCELLED            = 'CANCELLED';
    public const STATUS_NO_SHOW              = 'NO_SHOW';
    public const STATUS_IN_HOUSE             = 'IN_HOUSE';
    public const STATUS_COMPLETED            = 'COMPLETED';

    protected static array $validTransitions = [
        self::STATUS_CART                 => [self::STATUS_WAITING_PAYMENT, self::STATUS_WAITING_CONFIRMATION, self::STATUS_CANCELLED],
        self::STATUS_WAITING_PAYMENT      => [self::STATUS_WAITING_CONFIRMATION, self::STATUS_OVERDUE, self::STATUS_CANCELLED],
        self::STATUS_WAITING_CONFIRMATION => [self::STATUS_CONFIRMED, self::STATUS_CANCELLED],
        self::STATUS_OVERDUE              => [self::STATUS_WAITING_PAYMENT, self::STATUS_CANCELLED],
        self::STATUS_CONFIRMED            => [self::STATUS_CANCELLED, self::STATUS_IN_HOUSE, self::STATUS_NO_SHOW],
        self::STATUS_CANCELLED            => [],
        self::STATUS_IN_HOUSE             => [self::STATUS_COMPLETED],
        self::STATUS_COMPLETED            => [],
        self::STATUS_NO_SHOW              => [],
    ];
}
