<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Room Types redesign (mockup batch) — two real new fields, not
 * cosmetic-only:
 *
 * `code`: the short badge shown next to the name (e.g. "DLX", "EXS").
 * Nullable so the room types that already exist (created before this
 * field existed) don't break — RoomTypeController falls back to the
 * first 3 letters of the name for any row that has none, computed at
 * render time, never backfilled as fake "original" data.
 *
 * `is_active`: whether the type is currently offered for new bookings.
 * Genuinely new information — previously a room type's only "state"
 * was implicit (how many rooms happened to be assigned to it), which
 * meant a hotel could never mark "we're not offering this room type
 * for now" without deleting it (destroying its history) or physically
 * unassigning every room. Defaults to 1 so every existing row keeps
 * behaving exactly as before.
 */
class AddCodeAndStatusToRoomTypes extends Migration
{
    public function up()
    {
        $this->forge->addColumn('room_types', [
            'code' => [
                'type'       => 'VARCHAR',
                'constraint' => 10,
                'null'       => true,
                'after'      => 'name',
            ],
            'is_active' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 1,
                'after'      => 'photo_path',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('room_types', ['code', 'is_active']);
    }
}
