<?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('trial_configurations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('plan_id')->constrained()->onDelete('cascade');
            $table->boolean('trial_enabled')->default(false);
            $table->integer('trial_duration_days')->default(14);
            $table->boolean('trial_requires_payment_method')->default(true);
            $table->boolean('trial_auto_converts')->default(true);
            $table->string('trial_conversion_action')->default('upgrade_to_paid'); // upgrade_to_paid, cancel, notify
            $table->integer('trial_extension_limit')->default(0); // Max extensions allowed
            $table->json('trial_feature_overrides')->nullable(); // Features to limit during trial
            $table->text('trial_welcome_message')->nullable();
            $table->text('trial_expiry_message')->nullable();
            $table->timestamps();

            $table->unique(['plan_id']);
            $table->index(['trial_enabled']);
        });
    }

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