<?php

namespace app\enum;

enum ServerStatus : int
{
    /**
     * 等待开始
     */
    case WAITING = 0;
    /**
     * 进行中
     */
    case WORKING = 1;
    /**
     * 审核中
     */
    case AUDITING = 2;
    /**
     * 结算中
     */
    case SETTLEMENT = 3;
    /**
     * 任务完成
     */
    case COMPLETE = 4;
    /**
     * 任务失败
     */
    case FAILED = -1;
    /**
     * 获取所有状态映射数组
     */
    public static function toArray(): array
    {
        return [
            self::WAITING->value => __('waiting'),
            self::WORKING->value => __('working'),
            self::AUDITING->value => __('auditing'),
            self::SETTLEMENT->value => __('settlement'),
            self::COMPLETE->value => __('complete'),
            self::FAILED->value => __('failed'),
        ];
    }

    /**
     * 获取当前状态的描述文本
     */
    public function getDescription(): string
    {
        return self::toArray()[$this->value];
    }

    /**
     * 安全地从值创建枚举实例
     */
    public static function tryFromValue(int $value): ?self
    {
        return self::tryFrom($value);
    }
}
