<?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('facebook_integrations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('customer_id')->constrained()->onDelete('cascade');
            $table->string('service_type'); // monthly_subscription_limited, one_time_service, etc.
            $table->foreignId('assigned_employee_id')->constrained('users')->onDelete('cascade');
            $table->string('facebook_user_id')->nullable();
            $table->text('access_token')->nullable();
            $table->timestamp('token_expires_at')->nullable();
            $table->string('connection_status')->default('pending_connection'); // pending_connection, connected, expired, disconnected
            $table->timestamps();

            // Ensure one integration per customer
            $table->unique('customer_id');
        });
    }

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