/**
 * PTY permission request ID format utilities.
 *
 * PTY-sourced permission requests use UUID-format requestIds to distinguish
 * from channel-sourced requests (5-letter alphanumeric). These utilities
 * help identify the source of a permission request from its ID format.
 *
 * Mirrors the Swift-side distinction:
 * - Channel: 5-letter alphanumeric (e.g., "aB3xZ") from Claude Code's MCP protocol
 * - PTY: UUID v4 format (e.g., "550e8400-e29b-41d4-a716-446655440000") generated by PTYPermissionParser
 */

const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
const CHANNEL_ID_PATTERN = /^[a-zA-Z0-9]{5}$/;

/**
 * Returns true if the requestId matches UUID format (PTY-sourced).
 */
export function isPtyRequestId(requestId: string): boolean {
  return UUID_PATTERN.test(requestId);
}

/**
 * Returns true if the requestId matches 5-letter alphanumeric format (channel-sourced).
 */
export function isChannelRequestId(requestId: string): boolean {
  return CHANNEL_ID_PATTERN.test(requestId);
}

/**
 * Identifies the permission source from the requestId format.
 * Returns "channel", "pty", or "unknown".
 */
export function permissionSourceFromRequestId(requestId: string): "channel" | "pty" | "unknown" {
  if (isChannelRequestId(requestId)) return "channel";
  if (isPtyRequestId(requestId)) return "pty";
  return "unknown";
}
