<?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('product_import_histories', function (Blueprint $table) {
            $table->id();
            $table->string('scope', 30);
            $table->foreignId('merchant_id')->nullable()->constrained('merchants')->nullOnDelete();
            $table->foreignId('admin_id')->nullable()->constrained('admins')->nullOnDelete();
            $table->string('file_name');
            $table->unsignedInteger('success_count')->default(0);
            $table->unsignedInteger('failed_count')->default(0);
            $table->string('failure_file')->nullable();
            $table->timestamp('imported_at');
            $table->timestamps();

            $table->index(['scope', 'imported_at']);
            $table->index(['merchant_id', 'imported_at']);
        });
    }

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