<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('ratings', function (Blueprint $table) {
            $table->foreignId('rate_my_pay_id')->constrained()->onDelete('cascade');
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->tinyInteger('rating')->unsigned()->nullable(); // 1-5 stars
            $table->decimal('salary', 12, 2)->nullable();
            $table->timestamps();
            
            // Ensure a user can only rate a pay once
            $table->unique(['rate_my_pay_id', 'user_id']);
            
            // Indexes
            $table->index(['rate_my_pay_id']);
            $table->index(['user_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ratings');
    }
};
