namespace w4c_workflows.Models.Nodes;
// ---------------------------------------------------------------------------
// A declarative REST connector definition attached to a blueprint. It is what
// turns a plain catalog entry into a runnable integration node without a new C#
// executor per service: the blueprint says WHICH request to make, and the shared
// RestConnectorExecutor makes it (egress-vetted, quota-metered) and maps the
// response. Adding an integration should be data, not code.
//
// The URL is a template. `{name}` resolves from the node's (already
// interpolated) parameters; `{credential.field}` resolves from the field of the
// credential the blueprint references. Example (Telegram):
//
// baseUrl + path = "https://api.telegram.org" + "/bot{credential.token}/{operation}"
//
// Body/query come from a parameter holding a JSON object, so per-operation
// payloads stay in the workflow, not in the connector.
//
// A connector may declare a credential alias (injected by the shared executor
// through the credential type's strategy) and a success/error envelope
// (`successPath`/`errorPath`/`errorCodeMap`) for services that report failure in
// a HTTP 200 body. Both are data, so no provider-specific code enters the engine.
// ---------------------------------------------------------------------------
/// Where a connector gets its request body/query and how it maps the response.
public sealed record NodeConnector
{
/// Scheme + host (may itself contain {param}/{credential.field}).
public string BaseUrl { get; init; } = string.Empty;
/// Path template appended to .
public string Path { get; init; } = string.Empty;
/// HTTP method, e.g. POST.
public string Method { get; init; } = "POST";
/// Request body encoding: json, form or none.
public string ContentType { get; init; } = "json";
/// Parameter holding the JSON object sent as the body (null to send none).
public string? BodyParameter { get; init; } = "body";
/// Parameter holding a JSON object appended as query parameters.
public string? QueryParameter { get; init; } = "query";
/// Credential alias whose data backs {credential.*} placeholders.
public string? CredentialAlias { get; init; }
/// Dot path in the JSON response that holds the payload (e.g. result).
public string? ResponsePath { get; init; }
///
/// Dot path whose truthy value marks a successful response envelope (e.g.
/// ok). When set, a body that reports failure at HTTP 200 is turned
/// into a instead of a success item — some services
/// carry the outcome in the payload, not the status code. Data, not provider
/// code: the path lives in the connector JSON.
///
public string? SuccessPath { get; init; }
///
/// Dot path to the service error value used when is
/// falsy or missing (e.g. error). It is mapped through
/// and included in the failure message.
///
public string? ErrorPath { get; init; }
/// Dot path to extra error detail (e.g. the scopes a token is missing).
public string? ErrorDetailsPath { get; init; }
///
/// Maps a service error value (read from ) to our
/// stable failure code. Unmapped values fall back to connector_error,
/// so adding an error code stays a data change.
///
public Dictionary? ErrorCodeMap { get; init; }
}