<?php

declare(strict_types=1);

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

namespace App\Business\DataImport\Support;

use App\Business\DataImport\DataImportDefinitionRegistry;
use App\Business\DataImport\DataImportTypeDefinition;
use App\Business\DataImport\Enums\DataImportType;
use App\Business\DataImport\Handlers\CustomerCategoryImportHandler;
use App\Business\DataImport\Handlers\CustomerImportHandler;
use App\Business\DataImport\Handlers\OpeningStockImportHandler;
use App\Business\DataImport\Handlers\ProductBrandImportHandler;
use App\Business\DataImport\Handlers\ProductCategoryImportHandler;
use App\Business\DataImport\Handlers\ProductImportHandler;
use App\Business\DataImport\Handlers\SupplierCategoryImportHandler;
use App\Business\DataImport\Handlers\SupplierImportHandler;
use App\Business\DataImport\Handlers\UnitImportHandler;
use App\Business\DataImport\Handlers\WarehouseImportHandler;

final class HostBuiltInDataImportDefinitionBootstrap
{
    /**
     * @var array<string, class-string>
     */
    private const HANDLER_MAP = [
        DataImportType::Unit->value => UnitImportHandler::class,
        DataImportType::ProductCategory->value => ProductCategoryImportHandler::class,
        DataImportType::ProductBrand->value => ProductBrandImportHandler::class,
        DataImportType::Product->value => ProductImportHandler::class,
        DataImportType::CustomerCategory->value => CustomerCategoryImportHandler::class,
        DataImportType::Customer->value => CustomerImportHandler::class,
        DataImportType::SupplierCategory->value => SupplierCategoryImportHandler::class,
        DataImportType::Supplier->value => SupplierImportHandler::class,
        DataImportType::Warehouse->value => WarehouseImportHandler::class,
        DataImportType::OpeningStock->value => OpeningStockImportHandler::class,
    ];

    public function bootstrap(DataImportDefinitionRegistry $registry): void
    {
        foreach (self::HANDLER_MAP as $key => $handlerClass) {
            $type = DataImportType::from($key);

            $registry->register(new DataImportTypeDefinition(
                key: $key,
                label: $type->label(),
                handlerClass: $handlerClass,
                builtin: true,
            ));
        }
    }
}
