namespace AnthropicClient.Models; /// /// Represents a tool call result. /// public class ToolCallResult { private T? _value = default!; /// /// The value of the tool call result. Can be null if the call failed, the call was successful but the return type is void or Task, or the call was successful but the return value is null /// /// Thrown when the result is not successful. public T? Value { get { return IsSuccess ? _value : throw new InvalidOperationException("The result is not successful. Check the error property for more information."); } private set { _value = value; } } private Exception _error = default!; /// /// The error of the tool call result. /// /// Thrown when the result is successful. public Exception Error { get { return IsSuccess ? throw new InvalidOperationException("The result is successful. Check the value property for more information.") : _error; } private set { _error = value; } } /// /// Indicates whether the tool call was successful. /// public bool IsSuccess { get; } /// /// Indicates whether the tool call failed. /// public bool IsFailure => !IsSuccess; /// /// Initializes a new instance of the class. /// /// The value of the tool call result. /// The error of the tool call result. /// Indicates whether the tool call was successful. /// A new instance of the class. protected ToolCallResult(T? value, Exception error, bool isSuccess) { Value = value; Error = error; IsSuccess = isSuccess; } /// /// Creates a successful tool call result. /// /// The value of the tool call result. /// A new instance of the class. public static ToolCallResult Success(T? value) { return new ToolCallResult(value, null!, true); } /// /// Creates a failed ool call result. /// /// The error of the tool call result. /// A new instance of the class. public static ToolCallResult Failure(Exception error) { return new ToolCallResult(default!, error, false); } }