<?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('plugin_source_snapshots', function (Blueprint $table) {
            $table->id();
            $table->string('source_hash', 64)->unique();
            $table->unsignedInteger('tracked_file_count')->default(0);
            $table->timestamps();
        });

        Schema::create('plugin_file_changes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('plugin_source_snapshot_id')->constrained('plugin_source_snapshots')->cascadeOnDelete();
            $table->string('path');
            $table->string('change_type', 20);
            $table->string('previous_hash', 64)->nullable();
            $table->string('current_hash', 64)->nullable();
            $table->timestamps();
        });
    }

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