<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * The "dining accounts" half of corporate account management — an F&B-
 * only corporate client (never a room guest) can now be billed directly.
 * Only meaningful on the "pay directly" settlement path (see
 * PosOrderModel::settleDirect()): a charge-to-room order already bills
 * through the guest's own stay folio, so tagging a corporate account
 * there would silently redirect billing for their entire stay as a side
 * effect of one F&B order — deliberately not done.
 */
class AddCorporateAccountToPosOrders extends Migration
{
    public function up()
    {
        $this->forge->addColumn('pos_orders', [
            'corporate_account_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'after'      => 'guest_id',
            ],
        ]);

        $this->forge->addForeignKey('corporate_account_id', 'corporate_accounts', 'id', '', 'SET NULL');
        $this->forge->processIndexes('pos_orders');
    }

    public function down()
    {
        $this->forge->dropForeignKey('pos_orders', 'pos_orders_corporate_account_id_foreign');
        $this->forge->dropColumn('pos_orders', 'corporate_account_id');
    }
}
