<?php

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

/**
 * The recommendation mark, moved onto the plan family it describes.
 *
 * `is_recommended` was `LandingController::RECOMMENDED`, a single hardcoded
 * key that always pointed at "team". It belongs on the FAMILY, not the
 * version: a version is what gets published and superseded, but "which one
 * plan we point a visitor towards" is a stance about the product line, not a
 * capability that changes with a price — freezing it per version would mean
 * the recommendation silently vanishing every time a new version is
 * published.
 *
 * Backfilled to "team" in the same statement that adds the column, so the
 * public page marks exactly the plan it already marked a moment ago, sourced
 * from the console instead of from code.
 */
return new class extends Migration
{
    private const RECOMMENDED = 'team';

    public function up(): void
    {
        Schema::table('plan_families', function (Blueprint $table) {
            $table->boolean('is_recommended')->default(false)->after('sales_enabled');
        });

        DB::table('plan_families')->where('key', self::RECOMMENDED)->update(['is_recommended' => true]);
    }

    public function down(): void
    {
        Schema::table('plan_families', function (Blueprint $table) {
            $table->dropColumn('is_recommended');
        });
    }
};
