<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $now = now();
        $currency = env('BILLING_CURRENCY', 'USD');

        DB::table('plans')->insert([
            [
                'key' => 'free',
                'name' => 'Free',
                'description' => '1 project. All editor features. Upgrade to export.',
                'currency' => $currency,
                'monthly_price_cents' => 0,
                'yearly_price_cents' => 0,
                'features' => json_encode(['can_export' => false, 'project_limit' => 1]),
                'is_active' => true,
                'position' => 0,
                'max_seats' => 1,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'pro',
                'name' => 'Pro',
                'description' => '10 projects with full export.',
                'currency' => $currency,
                'monthly_price_cents' => 750,
                'yearly_price_cents' => 8100,
                'features' => json_encode(['can_export' => true, 'project_limit' => 10]),
                'is_active' => true,
                'position' => 1,
                'max_seats' => 1,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'scale',
                'name' => 'Scale',
                'description' => 'Unlimited projects with full export.',
                'currency' => $currency,
                'monthly_price_cents' => 1500,
                'yearly_price_cents' => 16200,
                'features' => json_encode(['can_export' => true, 'project_limit' => null]),
                'is_active' => true,
                'position' => 2,
                'max_seats' => 1,
                'created_at' => $now,
                'updated_at' => $now,
            ],
        ]);
    }

    public function down(): void
    {
        DB::table('plans')->whereIn('key', ['free', 'pro', 'scale'])->delete();
    }
};
