<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Answers to an event's custom registration questions (see
 * CreateEventRegistrationFieldsTable). JSON-encoded map of
 * {field_id: answer} — a checkbox field's answer is an array of strings,
 * everything else is a plain string. That's the one place this diverges
 * from the flat-list shape of room_types.amenities/campaigns.audience_filter,
 * worth calling out here rather than leaving it a silent surprise.
 */
class AddCustomFieldValuesToEventRegistrations extends Migration
{
    public function up()
    {
        $this->forge->addColumn('event_registrations', [
            'custom_field_values' => [
                'type'    => 'TEXT',
                'null'    => true,
                'comment' => 'JSON map of {field_id: answer}. Checkbox answers are arrays of strings; everything else is a plain string.',
                'after'   => 'email',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('event_registrations', 'custom_field_values');
    }
}
