syntax = "proto3";

package nominal.ai.v1;

import 'google/protobuf/timestamp.proto';

// ModelProviderHealthService monitors the health and performance of the backing LLM model provider.
// It runs lightweight health checks every 5 minutes to measure provider responsiveness and reliability,
// independent of the complexity of user prompts.
service ModelProviderHealthService {
  // GetProviderStatus returns the current health status of the model provider based on recent health checks.
  // The status is HEALTHY if all checks in the last 30 minutes passed latency thresholds,
  // or DEGRADED if any checks exceeded latency thresholds or failed entirely.
  rpc GetProviderStatus(GetProviderStatusRequest) returns (GetProviderStatusResponse);
}

message GetProviderStatusRequest {}

message GetProviderStatusResponse {
  // Timestamp when the last status was determined
  google.protobuf.Timestamp timestamp = 1;
  // Status of the most recent health check probe
  ProviderStatus last_status = 2;
  // Aggregated status over the last 30 minutes (DEGRADED if any check failed or exceeded thresholds)
  // Deprecated: Use aggregated_status instead. This field is kept for backward compatibility.
  ProviderStatus aggregated_status_over_last_30m = 3 [deprecated = true];
  // Aggregated status over the last iterations, configurable in the BE (DEGRADED if any check failed or exceeded thresholds)
  ProviderStatus aggregated_status = 4;
}

message ProviderStatus {
  oneof status {
    Healthy healthy = 1;
    Degraded degraded = 2;
  }
}

message Healthy {}

message Degraded {
  DegradationReason reason = 1;
}

enum DegradationReason {
  DEGRADATION_REASON_UNSPECIFIED = 0;
  DEGRADATION_REASON_HIGH_LATENCY = 1;
  DEGRADATION_REASON_FAILURES = 2;
  DEGRADATION_REASON_HIGH_LATENCY_AND_FAILURES = 3;
}

message ProviderMetrics {
  int32 time_to_first_token_ms = 1;
  int32 total_time_ms = 2;
}
