<?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('messages', function (Blueprint $table) {
            $table->ulid('id')->primary();
            $table->foreignUlid('user_id')->constrained('users')->nullOnDelete();
            $table->string('sender_name');
            $table->string('sender_avatar_url')->nullable();
            $table->foreignUlid('conversation_id')->constrained('conversations')->cascadeOnDelete();
            $table->text('body')->nullable();
            $table->timestampTz('read_at')->nullable();
            $table->softDeletesTz();
            $table->timestampsTz();

        });
    }

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