-- Settings + Bot Text templates + Gateway config

CREATE TABLE IF NOT EXISTS app_settings (
  `key` VARCHAR(128) PRIMARY KEY,
  `value_json` JSON NOT NULL,
  `updated_at` INT UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE IF NOT EXISTS bot_texts (
  `key` VARCHAR(128) PRIMARY KEY,
  `text` TEXT NOT NULL,
  `updated_at` INT UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

-- Seed defaults (safe to run multiple times)
INSERT IGNORE INTO app_settings (`key`,`value_json`,`updated_at`) VALUES
('bot.channel_membership', JSON_OBJECT('enabled',0,'channel_username',''), UNIX_TIMESTAMP()),
('bot.username_generation', JSON_OBJECT('method','random_8','methods',JSON_ARRAY('random_8','random_10','phone_last8','telegram_id','incremental','custom_prefix')), UNIX_TIMESTAMP()),
('payments.gateways', JSON_OBJECT('card_to_card', JSON_OBJECT('enabled',0,'cards',JSON_ARRAY()), 'nowpayments', JSON_OBJECT('enabled',0,'api_key','', 'ipn_secret','', 'currency','USDT'), 'aqayepardakht', JSON_OBJECT('enabled',0,'merchant_id','', 'callback_url','')), UNIX_TIMESTAMP()),
('trial', JSON_OBJECT('enabled',1,'max_per_user',1,'days',1,'traffic_gb',1), UNIX_TIMESTAMP());
