<?php

declare(strict_types=1);

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

namespace App\Support\Print;

use App\Support\Print\Contracts\DberpDocumentPrintPresenter;
use App\Support\Print\Documents\OtherStockInPrintPresenter;
use App\Support\Print\Documents\OtherStockOutPrintPresenter;
use App\Support\Print\Documents\PaymentOrderPrintPresenter;
use App\Support\Print\Documents\PurchaseOrderPrintPresenter;
use App\Support\Print\Documents\PurchaseReceiptPrintPresenter;
use App\Support\Print\Documents\PurchaseReturnPrintPresenter;
use App\Support\Print\Documents\ReceiptOrderPrintPresenter;
use App\Support\Print\Documents\SalesOrderPrintPresenter;
use App\Support\Print\Documents\SalesOutboundPrintPresenter;
use App\Support\Print\Documents\SalesReturnPrintPresenter;
use App\Support\Print\Documents\StocktakeOrderPrintPresenter;
use App\Support\Print\Documents\TransferOrderPrintPresenter;
use Illuminate\Contracts\Container\Container;

final class DberpDocumentPrintRegistry
{
    /**
     * @var array<string, class-string<DberpDocumentPrintPresenter>>
     */
    private const PRESENTERS = [
        PurchaseOrderPrintPresenter::DOCUMENT_KEY => PurchaseOrderPrintPresenter::class,
        PurchaseReceiptPrintPresenter::DOCUMENT_KEY => PurchaseReceiptPrintPresenter::class,
        SalesOrderPrintPresenter::DOCUMENT_KEY => SalesOrderPrintPresenter::class,
        SalesOutboundPrintPresenter::DOCUMENT_KEY => SalesOutboundPrintPresenter::class,
        TransferOrderPrintPresenter::DOCUMENT_KEY => TransferOrderPrintPresenter::class,
        StocktakeOrderPrintPresenter::DOCUMENT_KEY => StocktakeOrderPrintPresenter::class,
        ReceiptOrderPrintPresenter::DOCUMENT_KEY => ReceiptOrderPrintPresenter::class,
        PaymentOrderPrintPresenter::DOCUMENT_KEY => PaymentOrderPrintPresenter::class,
        PurchaseReturnPrintPresenter::DOCUMENT_KEY => PurchaseReturnPrintPresenter::class,
        SalesReturnPrintPresenter::DOCUMENT_KEY => SalesReturnPrintPresenter::class,
        OtherStockInPrintPresenter::DOCUMENT_KEY => OtherStockInPrintPresenter::class,
        OtherStockOutPrintPresenter::DOCUMENT_KEY => OtherStockOutPrintPresenter::class,
    ];

    public function __construct(
        private readonly Container $container,
    ) {}

    public function resolve(string $documentKey): DberpDocumentPrintPresenter
    {
        $class = self::PRESENTERS[$documentKey] ?? null;

        if ($class === null) {
            abort(404);
        }

        return $this->container->make($class);
    }

    public function supports(string $documentKey): bool
    {
        return isset(self::PRESENTERS[$documentKey]);
    }
}
