/**
 * Support agent tool registry.
 *
 * Assembles TOOL_SCHEMAS and TOOL_IMPLS from per-tool files.
 * SUPPORT_AGENT_NAME and ToolName are exported from here for consumer imports.
 */

import { type z } from 'zod';
import type { ToolImpl } from './_types.js';
import { getTicketTool } from './get-ticket.js';
import { getCaseTool } from './get-case.js';
import { getTransactionTool } from './get-transaction.js';
import { getRedemptionLogTool } from './get-redemption-log.js';
import { getUserHistoryTool } from './get-user-history.js';
import { getVendorHistoryTool } from './get-vendor-history.js';
import { listAttachmentsTool } from './list-attachments.js';
import { readImageTool } from './read-image.js';
import { searchKbTool } from './search-kb.js';
import { postMessageTool } from './post-message.js';
import { requestEvidenceTool } from './request-evidence.js';
import { setCategoryTool } from './set-category.js';
import { setPriorityTool } from './set-priority.js';
import { proposeResolutionTool } from './propose-resolution.js';
import { proposeRefundTool } from './propose-refund.js';
import { escalateToHumanTool } from './escalate-to-human.js';
import { closeTicketTool } from './close-ticket.js';

// ─── Agent name constant ──────────────────────────────────────────────────────

export const SUPPORT_AGENT_NAME = 'support_agent' as const;

// ─── Registry array ───────────────────────────────────────────────────────────

export const SUPPORT_TOOLS = [
  getTicketTool,
  getCaseTool,
  getTransactionTool,
  getRedemptionLogTool,
  getUserHistoryTool,
  getVendorHistoryTool,
  listAttachmentsTool,
  readImageTool,
  searchKbTool,
  postMessageTool,
  requestEvidenceTool,
  setCategoryTool,
  setPriorityTool,
  proposeResolutionTool,
  proposeRefundTool,
  escalateToHumanTool,
  closeTicketTool,
] as const;

// ─── Derived types and maps ───────────────────────────────────────────────────

export type ToolName = (typeof SUPPORT_TOOLS)[number]['name'];

export const TOOL_SCHEMAS: Record<ToolName, z.ZodType> = {
  get_ticket: getTicketTool.inputSchema,
  get_case: getCaseTool.inputSchema,
  get_transaction: getTransactionTool.inputSchema,
  get_redemption_log: getRedemptionLogTool.inputSchema,
  get_user_history: getUserHistoryTool.inputSchema,
  get_vendor_history: getVendorHistoryTool.inputSchema,
  list_attachments: listAttachmentsTool.inputSchema,
  read_image: readImageTool.inputSchema,
  search_kb: searchKbTool.inputSchema,
  post_message: postMessageTool.inputSchema,
  request_evidence: requestEvidenceTool.inputSchema,
  set_category: setCategoryTool.inputSchema,
  set_priority: setPriorityTool.inputSchema,
  propose_resolution: proposeResolutionTool.inputSchema,
  propose_refund: proposeRefundTool.inputSchema,
  escalate_to_human: escalateToHumanTool.inputSchema,
  close_ticket: closeTicketTool.inputSchema,
};

export const TOOL_IMPLS: Record<ToolName, ToolImpl<unknown>> = {
  get_ticket: getTicketTool.impl,
  get_case: getCaseTool.impl,
  get_transaction: getTransactionTool.impl,
  get_redemption_log: getRedemptionLogTool.impl,
  get_user_history: getUserHistoryTool.impl,
  get_vendor_history: getVendorHistoryTool.impl,
  list_attachments: listAttachmentsTool.impl,
  read_image: readImageTool.impl,
  search_kb: searchKbTool.impl,
  post_message: postMessageTool.impl,
  request_evidence: requestEvidenceTool.impl,
  set_category: setCategoryTool.impl,
  set_priority: setPriorityTool.impl,
  propose_resolution: proposeResolutionTool.impl,
  propose_refund: proposeRefundTool.impl,
  escalate_to_human: escalateToHumanTool.impl,
  close_ticket: closeTicketTool.impl,
};
