<?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('rate_my_pays', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('job_experience_id')->constrained()->onDelete('cascade');
            
            // Post Content
            $table->text('content');
            $table->boolean('is_anonymous')->default(false);
            $table->string('payslip_path')->nullable(); // File path for uploaded payslip
            
            // Salary details from job experience (snapshot at time of posting)
            $table->decimal('total_compensation', 12, 2);
            $table->decimal('base_salary', 12, 2);
            $table->decimal('bonus', 12, 2)->default(0);
            $table->decimal('equity', 12, 2)->default(0);
            $table->text('benefits')->nullable();
            $table->string('currency', 3)->default('NGN');
            
            // Engagement metrics
            $table->unsignedInteger('likes_count')->default(0);
            $table->unsignedInteger('comments_count')->default(0);
            $table->unsignedInteger('ratings_count')->default(0);
            $table->decimal('average_rating', 3, 2)->default(0);
        
            $table->timestamps();
            $table->softDeletes();
            
            // Indexes
            $table->index(['user_id', 'is_anonymous']);
            $table->index(['job_experience_id']);
        });
    }

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