<?php

declare(strict_types=1);

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

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('host_plugin_packages', function (Blueprint $table): void {
            $table->id();
            $table->string('plugin_code', 128)->index();
            $table->string('version', 64)->nullable();
            $table->string('package_id', 128)->nullable()->index();
            $table->string('package_name', 255)->nullable();
            $table->unsignedBigInteger('package_size')->nullable();
            $table->string('checksum', 128)->nullable();
            $table->string('checksum_algorithm', 32)->nullable();
            $table->text('signature')->nullable();
            $table->string('download_status', 32)->default('pending');
            $table->string('download_message', 512)->nullable();
            $table->string('download_error_code', 64)->nullable();
            $table->string('download_request_id', 128)->nullable();
            $table->string('local_path', 512)->nullable();
            $table->string('local_filename', 255)->nullable();
            $table->unsignedBigInteger('local_size')->nullable();
            $table->boolean('verified')->default(false);
            $table->timestamp('verified_at')->nullable();
            $table->timestamp('downloaded_at')->nullable();
            $table->json('raw_payload')->nullable();
            $table->timestamps();

            $table->index(['plugin_code', 'version']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('host_plugin_packages');
    }
};
