<?php

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('kylin_files', function (Blueprint $table) {
            $table->id();
            $table->string('driver', 30)->default('local')->comment('存储驱动: local/qiniu/tencent/aliyun/huawei/s3/kingsoft/baidu');
            $table->string('path', 500)->comment('文件路径');
            $table->string('original_name', 255)->comment('原始文件名');
            $table->string('mime_type', 100)->nullable();
            $table->unsignedBigInteger('size')->default(0)->comment('文件大小(字节)');
            $table->string('hash', 64)->nullable()->comment('文件哈希');
            $table->string('model_type', 125)->nullable();
            $table->unsignedBigInteger('model_id')->nullable();
            $table->string('collection', 50)->default('default')->comment('集合');
            $table->json('metadata')->nullable();
            $table->unsignedBigInteger('user_id')->nullable()->comment('上传者');
            $table->timestamps();
            $table->softDeletes();
            $table->index(['model_type', 'model_id']);
            $table->index('hash');
            $table->index(['driver', 'hash']);
            $table->index('collection');
        });
    }

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