<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Control DB. Key/value store for PLATFORM-level config — most notably
 * the platform's own Hubtel Checkout credentials used to collect
 * subscription payments from hotels. This is a distinct Hubtel merchant
 * context from any tenant's own `tenant_settings` (which holds that
 * hotel's Hubtel account for collecting from ITS guests). Same rule
 * applies here as there: never hardcoded, never in .env — see
 * App\Libraries\PlatformSettings, which encrypts secret/token values the
 * same way App\Libraries\Settings does for tenant_settings.
 */
class CreatePlatformSettingsTable 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('platform_settings');
    }

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