<?php

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

/**
 * Migration: Create google_meet_configurations table
 * 
 * This table stores OAuth2 credentials and tokens for Google Meet API integration.
 * All sensitive fields are encrypted at rest using Laravel's encryption.
 * 
 * @see https://developers.google.com/identity/protocols/oauth2
 */
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('google_meet_configurations', function (Blueprint $table) {
            // Primary key
            $table->id();

            // OAuth2 Credentials (encrypted at rest)
            $table->text('client_id');           // Google OAuth2 Client ID (encrypted)
            $table->text('client_secret');       // Google OAuth2 Client Secret (encrypted)
            $table->string('redirect_uri', 191); // OAuth2 callback URL

            // OAuth2 Tokens (encrypted at rest)
            $table->text('access_token')->nullable();       // Access token (encrypted)
            $table->text('refresh_token')->nullable();      // Refresh token (encrypted)
            $table->timestamp('token_expires_at')->nullable(); // Token expiration timestamp

            // Configuration Status
            $table->boolean('is_active')->default(true);    // Whether this configuration is active

            // Timestamps
            $table->timestamps();

            // Indexes
            $table->index('is_active');
            $table->index('created_at');
        });
    }

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