<?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_feature_limits', function (Blueprint $table) {
            $table->id();
            $table->foreignId('plan_id')->constrained()->onDelete('cascade');
            $table->foreignId('plan_feature_id')->constrained()->onDelete('cascade');
            $table->decimal('limit_value', 10, 2)->nullable(); // Numeric limit (e.g., 1000 emails)
            $table->boolean('is_enabled')->default(true); // Feature is enabled/disabled
            $table->string('limit_type')->default('monthly'); // monthly, daily, total
            $table->json('metadata')->nullable(); // Additional limit-specific data
            $table->boolean('applies_during_trial')->default(true); // Whether limit applies during trial
            $table->decimal('trial_limit_value', 10, 2)->nullable(); // Different limit for trial period
            $table->timestamps();

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

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