<?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('reviews', function (Blueprint $table) {
            $table->id();
            $table->foreignId('schedule_id')->constrained('schedules')->onDelete('cascade');
            $table->string('origin'); // 'providers' | 'clients'
            $table->unsignedBigInteger('origin_id');
            $table->decimal('stars', 2, 1);
            $table->text('comment')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index('schedule_id');
            $table->index(['origin', 'origin_id']);
            $table->index('deleted_at');
        });
    }

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