<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Database\Migrations\TenantMigration;
return new class extends TenantMigration
{
    public function up()
    {
        Schema::create('email_scheduled', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('template_id')->nullable();
            $table->string('subject');
            $table->longText('content');
            $table->timestamp('scheduled_at');
            $table->enum('status', ['scheduled', 'sending', 'sent', 'failed'])->default('scheduled');
            $table->unsignedBigInteger('created_by');
            $table->json('delivery_report')->nullable();
            $table->timestamps();

            $table->foreign('template_id')->references('id')->on('email_templates')->onDelete('set null');
            $table->foreign('created_by')->references('id')->on('users');
        });
    }

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