<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddExternalParentInfoToEventCharges extends Migration
{
    public function up()
    {
        $fields = [
            'external_parent_firstname' => [
                'type' => 'VARCHAR',
                'constraint' => 150,
                'null' => true,
                'after' => 'external_note',
            ],
            'external_parent_lastname' => [
                'type' => 'VARCHAR',
                'constraint' => 150,
                'null' => true,
            ],
            'external_parent_phone' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => true,
            ],
        ];

        if (! $this->db->fieldExists('external_parent_firstname', 'event_charges')) {
            $this->forge->addColumn('event_charges', $fields);
        }
    }

    public function down()
    {
        foreach (['external_parent_firstname', 'external_parent_lastname', 'external_parent_phone'] as $field) {
            if ($this->db->fieldExists($field, 'event_charges')) {
                $this->forge->dropColumn('event_charges', $field);
            }
        }
    }
}
