<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Real "Services/Extras" catalog (breakfast, airport transfer, extra bed,
 * ...) for the New Booking wizard's Add Services step — see
 * BookingServiceItemModel for why selections are stored per-booking
 * rather than posted straight to a folio (no folio exists until
 * check-in). Same pattern as room_types/menu_items: empty by default for
 * a freshly-provisioned tenant, managed for real through
 * ServiceCatalogController, not a hardcoded list.
 */
class CreateHotelServicesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 150,
            ],
            'description' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
                'null' => true,
            ],
            'category' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'default'    => 'other',
            ],
            'price' => [
                'type'       => 'DECIMAL',
                'constraint' => '10,2',
            ],
            'unit_label' => [
                'type'       => 'VARCHAR',
                'constraint' => 30,
                'default'    => 'flat',
            ],
            'is_active' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 1,
            ],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->createTable('hotel_services');
    }

    public function down()
    {
        $this->forge->dropTable('hotel_services', true);
    }
}
