<?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('notifications', function (Blueprint $table) {
            $table->id();

            // User who receives the notification
            $table->unsignedBigInteger('user_id');

            // Who triggered the notification (optional)
            $table->unsignedBigInteger('actor_id')->nullable();

            // Notification type
            $table->string('type');

            // Polymorphic relation (listing, message, booking, etc.)
            $table->morphs('notifiable');

            // Title and message
            $table->string('title');
            $table->text('message')->nullable();

            // Extra data (JSON)
            $table->json('data')->nullable();

            // Read status
            $table->boolean('is_read')->default(false);
            $table->timestamp('read_at')->nullable();

            $table->timestamps();

            // Indexes
            $table->index('user_id');
            $table->index('actor_id');
        });
    }

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