<?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('calendarsubscriptions', function (Blueprint $table) {
            // keep these nullable so legacy rows work without backfill
            $table->string('last_sync_status', 20)->nullable()->after('lastmodified');
            $table->text('last_sync_error')->nullable()->after('last_sync_status');
            $table->timestamp('last_sync_at')->nullable()->after('last_sync_error');

            // optional but handy for querying in the ui
            $table->index('last_sync_status');
            $table->index('last_sync_at');
        });
    }

    public function down(): void
    {
        Schema::table('calendarsubscriptions', function (Blueprint $table) {
            $table->dropIndex(['last_sync_status']);
            $table->dropIndex(['last_sync_at']);

            $table->dropColumn([
                'last_sync_status',
                'last_sync_error',
                'last_sync_at',
            ]);
        });
    }
};
