import Foundation

/// Decision → Claude permission-tool reply mapping (BACKEND_PROTOCOL §4.1, all
/// rows source-confirmed). `updatedInput` is echoed even when unchanged — the
/// docs direct you to always include it.
public enum ClaudeDecisionMapping {
    public static func reply(for decision: Decision, originalInput: JSONValue)
        -> MCPApprovalServer.Reply
    {
        switch decision {
        case .allow(let updatedInput):
            return .allow(updatedInput: updatedInput ?? originalInput)
        case .allowAlways:
            // Claude re-asks every time; the always-rule cache (ApprovalCoordinator)
            // auto-answers subsequent matches. This reply is a plain allow.
            return .allow(updatedInput: originalInput)
        case .deny(let reason):
            return .deny(message: reason ?? "Denied by user")
        case .cancelRun:
            // The adapter pairs this with interrupt() (ADAPTERS §1.2).
            return .deny(message: "Run canceled by user")
        }
    }
}
