<?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('premium_emails', function (Blueprint $table): void {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->string('message_id')->unique()->index();
            $table->string('subject')->nullable();
            $table->string('from_name')->nullable();
            $table->string('from_email');
            $table->text('to');
            $table->text('cc')->nullable();
            $table->text('bcc')->nullable();
            $table->dateTime('timestamp')->nullable();
            $table->longText('body_text')->nullable();
            $table->longText('body_html')->nullable();
            $table->boolean('is_seen')->default(false);
            $table->boolean('is_flagged')->default(false);
            $table->unsignedBigInteger('size')->nullable();
            $table->string('mailbox')->default('INBOX');
            $table->longText('raw_headers')->nullable();
            $table->longText('raw_body')->nullable();
            $table->json('attachments')->nullable();
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

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