<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Two real additions to the New Booking wizard, both previously
 * documented as deliberately NOT faked when this app had no way to
 * capture them for real (see BookingController::index()'s doc comment,
 * "no per-booking adult/child occupancy counts") — building them now
 * that there's an actual place to enter and use them.
 *
 * `adults`/`children`: real occupancy, defaults (1, 0) so every existing
 * booking keeps reading as "1 adult" rather than 0/blank.
 *
 * `initial_payment_amount`/`initial_payment_method`: a payment collected
 * in person at booking time (cash/mobile money/card), as distinct from
 * the existing deposit_amount+Hubtel-checkout-link flow (an online
 * payment the guest completes later, asynchronously). Nullable/unset for
 * every booking that doesn't use this path. Applied as a real
 * folio_payments row, dated to when it was actually collected, the
 * moment CheckInController opens the folio — never fabricated as if it
 * had been paid at check-in.
 */
class AddOccupancyAndInitialPaymentToBookings extends Migration
{
    public function up()
    {
        $this->forge->addColumn('bookings', [
            'adults' => [
                'type'       => 'INT',
                'constraint' => 3,
                'default'    => 1,
                'after'      => 'rate_applied',
            ],
            'children' => [
                'type'       => 'INT',
                'constraint' => 3,
                'default'    => 0,
                'after'      => 'adults',
            ],
            'initial_payment_amount' => [
                'type'       => 'DECIMAL',
                'constraint' => '10,2',
                'null'       => true,
                'after'      => 'children',
            ],
            'initial_payment_method' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'null'       => true,
                'after'      => 'initial_payment_amount',
            ],
            'initial_payment_applied' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 0,
                'after'      => 'initial_payment_method',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('bookings', ['adults', 'children', 'initial_payment_amount', 'initial_payment_method', 'initial_payment_applied']);
    }
}
