using AnthropicClient.Models; /// /// Represents the result of an Anthropic API operation. /// /// The type of the result value. public class AnthropicResult { private T _value = default!; /// /// The value of the result. /// /// 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 AnthropicError _error = default!; /// /// The error of the result. /// /// Thrown when the result is successful. public AnthropicError 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 operation was successful. /// public bool IsSuccess { get; } /// /// Indicates whether the operation failed. /// public bool IsFailure => !IsSuccess; /// /// The request ID of the operation. /// public AnthropicHeaders Headers { get; } /// /// Initializes a new instance of the class. /// /// The value of the result. /// The error of the result. /// Indicates whether the operation was successful. /// The Anthropic headers for the result. /// A new instance of the class. protected AnthropicResult(T value, AnthropicError error, bool isSuccess, AnthropicHeaders headers) { Value = value; Error = error; IsSuccess = isSuccess; Headers = headers; } /// /// Creates a successful result. /// /// The value of the result. /// The Anthropic headers for the result. /// A new instance of the class. public static AnthropicResult Success(T value, AnthropicHeaders headers) { return new AnthropicResult(value, null!, true, headers); } /// /// Creates a failed result. /// /// The error of the result. /// The Anthropic headers for the result. /// A new instance of the class. public static AnthropicResult Failure(AnthropicError error, AnthropicHeaders headers) { return new AnthropicResult(default!, error, false, headers); } }