<?php
namespace FleekDash\Database\Migrations;

use FleekDash\Database\Core\BaseMigration;
use FleekDash\Database\Core\TableBuilder;

/**
 * Create Notifications Tables
 *
 * Converted from Eloquent Schema to WordPress dbDelta
 */
return new class extends BaseMigration {

    public function up(): void
    {
        // Create notifications table
        $this->createTable('fleekdash_notifications', function (TableBuilder $table) {
            $table->id();
            $table->string('thread_id', 255)->nullable();
            $table->string('source', 100);
            $table->string('source_id', 255)->nullable();
            $table->longText('sender_info')->nullable()->comment('JSON data');
            $table->string('type', 50)->default('info');
            $table->string('status', 20)->default('unread');
            $table->string('subject', 500);
            $table->longText('message');
            $table->longText('actions')->nullable()->comment('JSON data');
            $table->longText('meta')->nullable()->comment('JSON metadata');
            $table->datetime('snoozed_until')->nullable();
            $table->datetime('resolved_at')->nullable();
            $table->integer('resolved_by')->nullable();
            $table->datetime('read_at')->nullable();
            $table->integer('read_by')->nullable();
            $table->timestamps();

            $table->index('status');
            $table->index('source');
            $table->index('type');
            $table->index('thread_id');
        });

        // Create notification notes table
        $this->createTable('fleekdash_notification_notes', function (TableBuilder $table) {
            $table->id();
            $table->unsignedBigInteger('notification_id');
            $table->integer('user_id');
            $table->text('note');
            $table->timestamps();

            $table->index('notification_id');
            $table->index('user_id');
        });
    }

    public function down(): void
    {
        $this->dropTable('fleekdash_notification_notes');
        $this->dropTable('fleekdash_notifications');
    }
};

