<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Tenant DB. Generic key/value store for per-hotel configuration that
 * doesn't need its own table. Nothing in Phase 1 writes to this — it
 * exists now so Phase 3 (Hubtel/WhatsApp credentials) and Phase 4
 * (Anthropic API key) can start writing rows without a migration touching
 * every live tenant database.
 */
class CreateTenantSettingsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'key' => [
                'type'       => 'VARCHAR',
                'constraint' => 100,
            ],
            'value' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('key');
        $this->forge->createTable('tenant_settings');
    }

    public function down()
    {
        $this->forge->dropTable('tenant_settings', true);
    }
}
