<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Business\Purchase\Enums;

/**
 * 采购订单收货进度筛选。取值由单据 status 派生，不是独立库字段。
 */
enum PurchaseOrderReceiptStatus: string
{
    case Unreceived = 'unreceived';
    case Partial = 'partial';
    case Received = 'received';
    case Open = 'open';

    /**
     * @return list<string>
     */
    public static function values(): array
    {
        return array_map(
            static fn (self $status): string => $status->value,
            self::cases(),
        );
    }

    /**
     * @return list<string>
     */
    public function statusValues(): array
    {
        return match ($this) {
            self::Unreceived => [PurchaseOrderStatus::Confirmed->value],
            self::Partial => [PurchaseOrderStatus::PartiallyReceived->value],
            self::Received => [PurchaseOrderStatus::FullyReceived->value],
            self::Open => [
                PurchaseOrderStatus::Confirmed->value,
                PurchaseOrderStatus::PartiallyReceived->value,
            ],
        };
    }

    public static function fromOrderStatus(string $status): ?self
    {
        return match ($status) {
            PurchaseOrderStatus::Confirmed->value => self::Unreceived,
            PurchaseOrderStatus::PartiallyReceived->value => self::Partial,
            PurchaseOrderStatus::FullyReceived->value => self::Received,
            default => null,
        };
    }
}
