// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Agents.AI.Workflows.Checkpointing;
namespace Microsoft.Agents.AI.Workflows;
///
/// Represents a request from an external input port.
///
/// The port invoked.
/// The unique identifier of the corresponding request.
/// The data contained in the response.
public record ExternalResponse(RequestPortInfo PortInfo, string RequestId, PortableValue Data)
{
///
/// Attempts to retrieve the underlying data as the specified type.
///
/// The type to which the data should be cast or converted.
/// The data cast to the specified type, or null if the data cannot be cast to the specified type.
public TValue? DataAs() => this.Data.As();
///
/// Determines whether the underlying data is of the specified type.
///
/// The type to compare with the underlying data.
/// true if the underlying data is of type TValue; otherwise, false.
public bool DataIs() => this.Data.Is();
///
/// Determines whether the underlying data can be retrieved as the specified type.
///
/// The type to which the underlying data is to be cast if available.
/// When this method returns, contains the value of type if the data is
/// available and compatible.
/// true if the data is present and can be cast to ; otherwise, false.
public bool DataIs([NotNullWhen(true)] out TValue? value) => this.Data.Is(out value);
///
/// Attempts to retrieve the underlying data as the specified type.
///
/// The type to which the data should be cast or converted.
/// The data cast to the specified type, or null if the data cannot be cast to the specified type.
public object? DataAs(Type targetType) => this.Data.AsType(targetType);
}