/**
 * Minimal shim for `openclaw/plugin-sdk`.
 *
 * The `@tencent-weixin/openclaw-weixin` npm package imports from
 * `openclaw/plugin-sdk` which is normally provided by the OpenClaw host.
 * VisionClaw provides this lightweight replacement so the package's
 * transport modules (api, cdn, auth, messaging, media) resolve without
 * installing the full OpenClaw runtime.
 *
 * Only the transport-layer functions are implemented faithfully; the
 * heavy framework functions (used in process-message.ts / channel.ts)
 * are no-op stubs since VisionClaw replaces those modules entirely.
 */

// ---------------------------------------------------------------------------
// Runtime functions used by transport modules we actually import
// ---------------------------------------------------------------------------

export function normalizeAccountId(id) {
  return id.replace(/[^a-z0-9-]/gi, "-").toLowerCase();
}

export function stripMarkdown(text) {
  return text
    .replace(/\*\*(.+?)\*\*/g, "$1")
    .replace(/__(.+?)__/g, "$1")
    .replace(/\*(.+?)\*/g, "$1")
    .replace(/_(.+?)_/g, "$1")
    .replace(/~~(.+?)~~/g, "$1")
    .replace(/^#{1,6}\s+/gm, "")
    .replace(/^[*-]\s+/gm, "")
    .replace(/^\d+\.\s+/gm, "");
}

export async function withFileLock(_path, _opts, fn) {
  return fn();
}

export function buildChannelConfigSchema(schema) {
  return { schema };
}

// ---------------------------------------------------------------------------
// Stub functions used only by process-message.ts / channel.ts
// (VisionClaw never imports those modules -- these exist solely so the
//  package's other modules don't fail to load due to re-exports.)
// ---------------------------------------------------------------------------

export function createTypingCallbacks(_opts) {
  return {
    start: async () => {},
    stop: async () => {},
  };
}

export function resolveSenderCommandAuthorizationWithRuntime(_opts) {
  return Promise.resolve({ senderAllowedForCommands: true, commandAuthorized: true });
}

export function resolveDirectDmAuthorizationOutcome(_opts) {
  return "allowed";
}

export function resolvePreferredOpenClawTmpDir() {
  return "/tmp/openclaw";
}

export function loadConfig() {
  return {};
}

export async function writeConfigFile(_config) {}
