namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
///
/// Command (Central UI → site DCL manager) to verify a data-connection endpoint
/// configuration without persisting it: connect, capture the server certificate if it
/// is untrusted, then disconnect. The probe is read-only and never trusts the server
/// certificate — an untrusted certificate is captured and the connect is rejected
/// (cert trust is a separate, later action). Only OPC UA is supported today; other
/// protocols return a with
/// .
///
/// Name of the data connection being verified (for logging/correlation).
/// Protocol type string (e.g. "OpcUa"); matched case-insensitively.
/// Serialized endpoint configuration JSON (the typed OPC UA endpoint shape).
///
/// Target site identifier — REQUIRED when the command is invoked via the management
/// HTTP API/CLI (the actor must route it to a site); ignored on the site side, where
/// routing already happened. Additive per the message-contract evolution rules.
///
public record VerifyEndpointCommand(string ConnectionName, string Protocol, string ConfigJson, string? SiteIdentifier = null);
///
/// Classification of why an endpoint verification failed. Distinguishes the cases the
/// Central UI must present differently — most importantly
/// , which carries a capturable server certificate the
/// operator can choose to trust in a later step.
///
public enum VerifyFailureKind
{
/// The endpoint host could not be reached (DNS failure, connection refused, socket error).
Unreachable,
/// The server rejected the supplied user identity (anonymous/username/certificate).
AuthFailed,
///
/// The server presented a certificate that is not trusted by this site. The
/// certificate is captured in so it can be
/// reviewed and trusted in a later step; the probe itself rejected it.
///
UntrustedCertificate,
/// The verification did not complete within the allotted time budget.
Timeout,
/// Any other server-side or unexpected failure (including unsupported protocol).
ServerError
}
///
/// Details of a server certificate captured during a verification probe. Carries the
/// fields the Central UI needs to display the certificate for an operator trust decision,
/// plus the raw DER (base64) so the certificate can be persisted to the trusted store
/// verbatim in a later step.
///
/// The certificate SHA-1 thumbprint (hex).
/// The certificate subject distinguished name.
/// The certificate issuer distinguished name.
/// The not-before validity bound (UTC).
/// The not-after validity bound (UTC).
/// The raw DER-encoded certificate, base64-encoded.
public record ServerCertInfo(
string Thumbprint,
string Subject,
string Issuer,
DateTime NotBeforeUtc,
DateTime NotAfterUtc,
string DerBase64);
///
/// Result of a . On success ,
/// , and are all null. On failure
/// classifies the failure and carries a
/// human-readable message; is populated only when
/// is .
///
/// True if a session was established (the endpoint config is valid and reachable).
/// The failure classification, or null on success.
/// A human-readable error message, or null on success.
/// The captured untrusted server certificate, or null.
public record VerifyEndpointResult(
bool Success,
VerifyFailureKind? FailureKind,
string? Error,
ServerCertInfo? Cert);