<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('activities', function (Blueprint $table) {
            $table->string('lifecycle_status')->default('planned')->index();
            $table->string('outcome')->nullable();
            $table->string('meeting_type')->nullable();
            $table->text('agenda')->nullable();
            $table->dateTime('remind_at')->nullable();
            $table->string('visibility')->default('team');
            $table->json('to_recipients')->nullable();
            $table->json('cc_recipients')->nullable();
            $table->json('bcc_recipients')->nullable();
            $table->string('email_status')->nullable()->index();
            $table->dateTime('scheduled_at')->nullable();
            $table->dateTime('sent_at')->nullable();
            $table->dateTime('opened_at')->nullable();
            $table->dateTime('replied_at')->nullable();
            $table->string('category')->nullable();
        });
        Schema::table('notes', fn (Blueprint $table) => $table->string('visibility')->default('team'));
        Schema::create('activity_attendees', function (Blueprint $table) {
            $table->id();
            $table->foreignId('activity_id')->index();
            $table->foreignId('user_id')->index();
            $table->string('response')->default('invited');
            $table->timestamps();
            $table->unique(['activity_id', 'user_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('activity_attendees');
        Schema::table('notes', fn (Blueprint $table) => $table->dropColumn('visibility'));
        Schema::table('activities', fn (Blueprint $table) => $table->dropColumn([
            'lifecycle_status', 'outcome', 'meeting_type', 'agenda', 'remind_at',
            'visibility', 'to_recipients', 'cc_recipients', 'bcc_recipients',
            'email_status', 'scheduled_at', 'sent_at', 'opened_at', 'replied_at', 'category',
        ]));
    }
};
