<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

// ══════════════════════════════════════════════════════════════════
//  InPractice — Notifications Table
//
//  Unified notification inbox for all platform activity.
//
//  Notification types:
//    job_match         → employer sent you a job interest
//    job_accepted      → professional accepted your job notification
//    job_connected     → contact details shared (both consented)
//    freelance_brief   → a new brief matches your freelance profile
//    freelance_interest→ seeker is interested in your profile
//    freelance_connected → contact details shared
//    forum_reply       → someone replied to your forum post
//    forum_like        → someone liked your post or reply
//    survey_new        → a new survey is available for you
//    document_new      → a new document added to your hub
//    review_received   → you received a new review
//    system            → general platform announcement
//
//  Uses Laravel's built-in notifications structure
//  so push notifications via PWA work seamlessly.
// ══════════════════════════════════════════════════════════════════

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('notifications', function (Blueprint $table) {
            $table->uuid('id')->primary();

            // ── Recipient ─────────────────────────────────────
            $table->string('notifiable_type');               // always 'App\Models\User'
            $table->unsignedBigInteger('notifiable_id');
            $table->index(['notifiable_type', 'notifiable_id']);

            // ── Notification Type ─────────────────────────────
            $table->string('type');                          // class name or our custom type slug

            // ── Payload ───────────────────────────────────────
            // Stores all notification data as JSON
            // e.g. { "message": "...", "link": "/forum/post/5", "actor": "NickName" }
            $table->json('data');

            // ── Read Status ───────────────────────────────────
            $table->timestamp('read_at')->nullable();        // null = unread

            $table->timestamps();
        });
    }

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