<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Tags a folio as billable to a corporate account for the monthly
 * statement PDF — independent of Phase 1's payer_allocations (which
 * record who pays how much); this is just "which company gets this
 * folio's charges rolled into their statement."
 */
class AddCorporateAccountToFolios extends Migration
{
    public function up()
    {
        $this->forge->addColumn('folios', [
            '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('folios');
    }

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