<?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('meet_messages', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->string('owner_ref')->index();
            $table->foreignId('session_id')->constrained('meet_sessions')->cascadeOnDelete();
            $table->string('sender_ref')->nullable();
            $table->string('sender_name');
            $table->string('type')->default('public'); // public, private
            $table->string('recipient_ref')->nullable();
            $table->text('body');
            $table->json('metadata')->nullable();
            $table->timestamps();
            $table->index(['session_id', 'created_at']);
        });

        Schema::create('meet_reactions', function (Blueprint $table) {
            $table->id();
            $table->string('owner_ref')->index();
            $table->foreignId('session_id')->constrained('meet_sessions')->cascadeOnDelete();
            $table->string('participant_ref')->nullable();
            $table->string('sender_name');
            $table->string('emoji', 32);
            $table->timestamps();
            $table->index(['session_id', 'created_at']);
        });
    }

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