<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('plans', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->text('description')->nullable();

            // Precios (en menor unidad: COP centavos no aplica, pero usamos decimal grande)
            $table->decimal('price_monthly', 12, 2)->default(0);
            $table->decimal('price_yearly', 12, 2)->default(0);
            $table->string('currency', 3)->default('COP');

            // Promoción interna del plan
            $table->decimal('promo_price_monthly', 12, 2)->nullable();
            $table->decimal('promo_price_yearly', 12, 2)->nullable();
            $table->date('promo_starts_at')->nullable();
            $table->date('promo_ends_at')->nullable();

            // Límites duros (null = ilimitado)
            $table->unsignedInteger('max_employees')->nullable();
            $table->unsignedInteger('max_services')->nullable();
            $table->unsignedInteger('max_bookings_month')->nullable();
            $table->unsignedInteger('max_branches')->nullable()->default(1);
            $table->unsignedInteger('max_customers')->nullable();

            $table->boolean('is_active')->default(true);
            $table->boolean('is_featured')->default(false);
            $table->boolean('is_public')->default(true);
            $table->unsignedInteger('trial_days')->default(14);
            $table->unsignedInteger('sort_order')->default(0);

            $table->timestamps();
            $table->softDeletes();

            $table->index(['is_active', 'is_public', 'sort_order']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('plans');
    }
};
