<?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('roster_result_rows', function (Blueprint $table) {
            $table->id();
            $table->foreignId('upload_id')->constrained('roster_result_uploads')->cascadeOnDelete();
            $table->string('team', 32);
            $table->date('roster_date');
            $table->string('user_name');
            $table->string('normalized_user_name');
            $table->decimal('total_hours', 6, 2)->nullable();
            $table->json('raw_payload')->nullable();
            $table->timestamps();

            $table->index(['team', 'roster_date']);
            $table->index(['upload_id', 'normalized_user_name']);
        });
    }

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