<?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::create('google_tokens', function (Blueprint $table) {
            $table->id();
            $table->text('access_token');
            $table->text('refresh_token')->nullable();
            $table->timestamp('expires_at')->nullable();
            $table->timestamps();

            $table->index('expires_at');
        });

        // Add attendee_responses to demo_schedules
        Schema::table('demo_schedules', function (Blueprint $table) {
            $table->json('attendee_responses')->nullable()->after('is_current');
            $table->timestamp('responses_synced_at')->nullable()->after('attendee_responses');
        });
    }

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

        Schema::table('demo_schedules', function (Blueprint $table) {
            $table->dropColumn(['attendee_responses', 'responses_synced_at']);
        });
    }
};
