<?php

declare(strict_types=1);

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

namespace App\Services\Plugin;

/**
 * 官方插件发布包安装前校验结果。
 */
final class HostPluginReleasePackageVerificationResult
{
    /**
     * @param  array<string, mixed>|null  $pluginManifest
     * @param  array<string, mixed>|null  $releaseManifest
     */
    public function __construct(
        public readonly bool $valid,
        public readonly ?string $errorCode = null,
        public readonly ?array $pluginManifest = null,
        public readonly ?array $releaseManifest = null,
        public readonly string $pluginRoot = '',
        public readonly string $alias = '',
        public readonly bool $signatureRequired = false,
        public readonly bool $signaturePresent = false,
        public readonly bool $signatureVerified = false,
    ) {}

    public static function failed(string $errorCode): self
    {
        return new self(valid: false, errorCode: $errorCode);
    }

    /**
     * @param  array<string, mixed>  $pluginManifest
     * @param  array<string, mixed>  $releaseManifest
     */
    public static function passed(
        array $pluginManifest,
        array $releaseManifest,
        string $pluginRoot,
        string $alias,
        bool $signatureRequired,
        bool $signaturePresent,
        bool $signatureVerified,
    ): self {
        return new self(
            valid: true,
            pluginManifest: $pluginManifest,
            releaseManifest: $releaseManifest,
            pluginRoot: $pluginRoot,
            alias: $alias,
            signatureRequired: $signatureRequired,
            signaturePresent: $signaturePresent,
            signatureVerified: $signatureVerified,
        );
    }
}
