<?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('plan_providers', function (Blueprint $table) {
            $table->id();
            $table->foreignId('plan_id')->constrained()->onDelete('cascade');
            $table->string('provider'); // stripe, lemon_squeezy, polar, etc.
            $table->string('provider_price_id')->nullable(); // Price ID from provider
            $table->string('provider_variant_id')->nullable(); // Variant ID from provider
            $table->string('provider_product_id')->nullable(); // Product ID from provider
            $table->boolean('is_enabled')->default(true);
            $table->decimal('price', 10, 2)->nullable();
            $table->string('currency', 3)->default('USD');
            $table->json('provider_data')->nullable(); // Provider-specific configuration
            $table->integer('sort_order')->default(0);
            $table->timestamps();

            $table->unique(['plan_id', 'provider']);
            $table->index(['plan_id', 'is_enabled']);
        });
    }

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