<?php

declare(strict_types=1);

namespace App\Support;

use App\Models\DberpProductSku;

/**
 * 报表与查询页中商品规格（SKU）展示口径（避免在界面暴露技术字段名）。
 */
final class DberpReportSkuPresentation
{
    public static function unspecifiedSpecLabel(): string
    {
        return __('dberp.labels.unspecified_product_spec');
    }

    /**
     * 库存结余行：无规格维度（历史或未绑定）时的业务提示。
     */
    public static function inventoryBalanceSpecSummary(?int $productSkuId, ?string $specText, ?string $skuCode): string
    {
        if ($productSkuId === null || $productSkuId === 0) {
            return self::unspecifiedSpecLabel();
        }

        $spec = trim((string) ($specText ?? ''));
        if ($spec !== '') {
            return $spec;
        }

        $code = trim((string) ($skuCode ?? ''));

        return $code !== '' ? $code : self::unspecifiedSpecLabel();
    }

    public static function skuRecordSpecSummary(?DberpProductSku $sku): string
    {
        if ($sku === null) {
            return self::unspecifiedSpecLabel();
        }

        return self::inventoryBalanceSpecSummary(
            (int) $sku->getKey(),
            (string) ($sku->spec_text ?? ''),
            (string) ($sku->sku_code ?? ''),
        );
    }
}
