<?php

namespace App\Support\SchoolYear;

final class SchoolYearStatus
{
    public const DRAFT = 'draft';
    public const ACTIVE = 'active';
    public const CLOSING = 'closing';
    public const CLOSED = 'closed';
    public const ARCHIVED = 'archived';

    public const ALL = [
        self::DRAFT,
        self::ACTIVE,
        self::CLOSING,
        self::CLOSED,
        self::ARCHIVED,
    ];

    public const TRANSITIONS = [
        self::DRAFT => [self::ACTIVE],
        self::ACTIVE => [self::CLOSING],
        self::CLOSING => [self::ACTIVE, self::CLOSED],
        self::CLOSED => [self::ACTIVE, self::ARCHIVED],
        self::ARCHIVED => [],
    ];

    public static function canTransition(string $from, string $to): bool
    {
        return in_array($to, self::TRANSITIONS[$from] ?? [], true);
    }

    public static function isReadonly(string $status): bool
    {
        return self::isLifecycleMetadataLocked($status);
    }

    public static function isLifecycleMetadataLocked(string $status): bool
    {
        return in_array($status, [self::CLOSED, self::ARCHIVED], true);
    }
}
