/// The result of an [IntegrationHealthCheck].
class HealthCheckResult {
  /// Whether the integration is reachable and responding correctly.
  final bool isHealthy;

  /// Human-readable description of the health status.
  final String message;

  /// Optional latency measurement for the health-check request.
  final Duration? latency;

  const HealthCheckResult({required this.isHealthy, required this.message, this.latency});

  /// Convenience constructor for a healthy result.
  const HealthCheckResult.healthy({this.message = 'OK', this.latency}) : isHealthy = true;

  /// Convenience constructor for an unhealthy result.
  const HealthCheckResult.unhealthy({required this.message}) : isHealthy = false, latency = null;

  @override
  String toString() => 'HealthCheckResult(healthy=$isHealthy, message=$message)';
}

/// Contract for verifying that an external integration is reachable and
/// correctly configured.
///
/// Each channel adapter (WooCommerce, Square, etc.) implements this interface
/// so the application can surface connectivity status on the dashboard and
/// before critical operations.
abstract class IntegrationHealthCheck {
  /// Performs a lightweight connectivity check against the remote API.
  ///
  /// Implementations should use the cheapest available endpoint (e.g. a
  /// system-status or ping endpoint) and return within a reasonable timeout.
  Future<HealthCheckResult> check();
}
