<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddPhonePePaymentSettings extends Migration
{
    public function up()
    {
        $rows = [
            ['key' => 'phonepe_client_id', 'value' => ''],
            ['key' => 'phonepe_client_version', 'value' => '1'],
            ['key' => 'phonepe_client_secret', 'value' => ''],
            ['key' => 'phonepe_webhook_url', 'value' => ''],
            ['key' => 'phonepe_webhook_username', 'value' => ''],
            ['key' => 'phonepe_webhook_password', 'value' => ''],
        ];
        foreach ($rows as $row) {
            $exists = $this->db->table('settings')->where('key', $row['key'])->countAllResults();
            if (!$exists) {
                $this->db->table('settings')->insert([
                    'key' => $row['key'],
                    'value' => $row['value'],
                    'created_at' => date('Y-m-d H:i:s'),
                ]);
            }
        }
    }

    public function down()
    {
        $this->db->table('settings')->whereIn('key', [
            'phonepe_client_id',
            'phonepe_client_version',
            'phonepe_client_secret',
            'phonepe_webhook_url',
            'phonepe_webhook_username',
            'phonepe_webhook_password',
        ])->delete();
    }
}
