<?php

namespace Kylin\Property\Enums;

/**
 * 维修工单状态枚举
 */
enum RepairStatus: string
{
    case PENDING = 'pending';
    case APPROVED = 'approved';
    case ASSIGNED = 'assigned';
    case PROCESSING = 'processing';
    case CONFIRMING = 'confirming';
    case COMPLETED = 'completed';
    case REJECTED = 'rejected';

    public function label(): string
    {
        return match ($this) {
            self::PENDING => '待审核',
            self::APPROVED => '已审核',
            self::ASSIGNED => '已派单',
            self::PROCESSING => '处理中',
            self::CONFIRMING => '待确认',
            self::COMPLETED => '已完成',
            self::REJECTED => '已驳回',
        };
    }

    public function canTransitionTo(self $status): bool
    {
        return match ($this) {
            self::PENDING => in_array($status, [self::APPROVED, self::REJECTED]),
            self::APPROVED => $status === self::ASSIGNED,
            self::ASSIGNED => $status === self::PROCESSING,
            self::PROCESSING => $status === self::CONFIRMING,
            self::CONFIRMING => $status === self::COMPLETED,
            default => false,
        };
    }
}
