<?php

declare(strict_types=1);

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

namespace App\Support\PluginIntegration;

use App\Models\DberpOtherStockInOrder;
use App\Models\DberpProduct;
use App\Models\DberpProductSku;
use App\Models\DberpPurchaseReceiptOrder;
use Closure;
use Filament\Actions\Action;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;

final class BarcodeLabelFilamentBridge
{
    private const INTEGRATION_CLASS = 'Loongdom\DberpBarcodeLabel\Filament\BarcodeLabelHostFilamentActions';

    /**
     * @param  (Closure(): ?DberpProduct)|null  $recordResolver
     * @return list<Action>
     */
    public static function productHeaderActions(?Closure $recordResolver = null): array
    {
        return self::call('productHeaderActions', [], $recordResolver);
    }

    /**
     * @return list<BulkActionGroup|BulkAction>
     */
    public static function productTableToolbarActions(): array
    {
        return self::call('productTableToolbarActions', []);
    }

    /**
     * @param  (Closure(DberpProductSku): bool)|null  $canViewHost
     * @return list<BulkActionGroup|BulkAction>
     */
    public static function skuRelationToolbarActions(?Closure $canViewHost = null): array
    {
        return self::call('skuRelationToolbarActions', [], $canViewHost);
    }

    /**
     * @param  (Closure(DberpProductSku): bool)|null  $canViewHost
     * @return list<Action>
     */
    public static function skuRecordActions(?Closure $canViewHost = null): array
    {
        return self::call('skuRecordActions', [], $canViewHost);
    }

    /**
     * @param  (Closure(DberpPurchaseReceiptOrder): bool)|null  $canViewHost
     * @return list<Action>
     */
    public static function purchaseReceiptHeaderActions(?Closure $canViewHost = null): array
    {
        return self::call('purchaseReceiptHeaderActions', [], $canViewHost);
    }

    /**
     * @param  (Closure(DberpOtherStockInOrder): bool)|null  $canViewHost
     * @return list<Action>
     */
    public static function otherStockInHeaderActions(?Closure $canViewHost = null): array
    {
        return self::call('otherStockInHeaderActions', [], $canViewHost);
    }

    private static function call(string $method, mixed $default, mixed ...$arguments): mixed
    {
        return OptionalPluginClassDelegate::call(
            self::INTEGRATION_CLASS,
            static fn (string $integrationClass): mixed => $integrationClass::$method(...$arguments),
            $default,
        );
    }
}
