// DEPRECATED: 仅作历史模板，生产 Agent 必须使用 wechat_hook_v2.js（FridaManager.DEFAULT_SCRIPT）。
// 本文件含 placeholder RPC，禁止用于矩阵验收或标 ✅。
'use strict';

function ok(data) { return { ok: true, data: data || null, ts: Date.now() }; }
function fail(message) { return { ok: false, error: String(message), ts: Date.now() }; }

function runJava(fn) {
  let result;
  Java.perform(function () {
    try { result = fn(); } catch (e) { result = fail(e.stack || e.message || e); }
  });
  return result;
}

rpc.exports = {
  ping: function () { return 'pong from wechat_hook_bridge'; },
  getConnectionStatus: function () {
    return ok({ java_available: Java.available, process: Process.id, arch: Process.arch, platform: Process.platform });
  },
  takeScreenshot: function () {
    // 截图建议在手机端通过 uiautomator/screencap 实现；Hook 层返回占位，Agent 可扩展真实文件路径。
    return ok({ mode: 'placeholder', message: '请在 mobile_agent 扩展 screencap -p 后回传文件路径' });
  },
  dumpUiTree: function () { return ok({ mode: 'placeholder', message: '建议通过 uiautomator dump 获取 UI XML' }); },
  goHome: function () { return ok({ action: 'goHome', message: '桥接模板未执行 UI 点击；请替换完整 Hook 后验证' }); },
  openContacts: function () { return ok({ action: 'openContacts', message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  openChats: function () { return ok({ action: 'openChats', message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  searchContact: function (keyword) { return ok({ keyword: keyword, message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  getContacts: function () { return ok({ contacts: [], message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  getContactProfile: function (wxid) { return ok({ wxid: wxid, message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  addFriend: function (keyword) { return fail('危险动作未在模板中实现：addFriend ' + keyword); },
  acceptFriend: function (wxid) { return fail('危险动作未在模板中实现：acceptFriend ' + wxid); },
  sendTextMessage: function (to, text) { return fail('危险动作未在模板中实现：sendTextMessage ' + to); },
  sendImageMessage: function (to, path) { return fail('危险动作未在模板中实现：sendImageMessage ' + to); },
  getMessages: function (wxid) { return ok({ wxid: wxid, messages: [], message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  openChat: function (wxid) { return ok({ wxid: wxid, message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  createGroup: function (members) { return fail('危险动作未在模板中实现：createGroup'); },
  inviteGroupMember: function (chatroom, members) { return fail('危险动作未在模板中实现：inviteGroupMember'); },
  getGroupMembers: function (chatroom) { return ok({ chatroom: chatroom, members: [], message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  browseChannels: function () { return ok({ message: 'NOT_IMPLEMENTED_IN_TEMPLATE' }); },
  addFavorite: function () { return fail('危险动作未在模板中实现：addFavorite'); },
  addCustomEmoji: function () { return fail('危险动作未在模板中实现：addCustomEmoji'); }
};
