<?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('report_snapshots', function (Blueprint $table) {
            $table->id();
            $table->enum('period', ['daily', 'weekly', 'monthly']);
            $table->date('from_date');
            $table->date('to_date');
            $table->json('payload');
            $table->foreignId('generated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['period', 'from_date', 'to_date']);
        });

        Schema::create('report_exports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('report_snapshot_id')->nullable()->constrained('report_snapshots')->nullOnDelete();
            $table->enum('format', ['pdf', 'csv'])->default('pdf');
            $table->string('file_path')->nullable();
            $table->string('status', 20)->default('generated');
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->softDeletes();
        });
    }

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