syntax = "proto3";

package sms;

enum ModelDeploymentPhase {
  MODEL_DEPLOYMENT_PHASE_UNSPECIFIED = 0;
  MODEL_DEPLOYMENT_PHASE_PENDING = 1;
  MODEL_DEPLOYMENT_PHASE_PULLING = 2;
  MODEL_DEPLOYMENT_PHASE_STARTING = 3;
  MODEL_DEPLOYMENT_PHASE_READY = 4;
  MODEL_DEPLOYMENT_PHASE_FAILED = 5;
  MODEL_DEPLOYMENT_PHASE_DELETING = 6;
}

message ModelDeploymentSpec {
  string target_node_uuid = 1;
  string provider = 2;
  string model = 3;
  map<string, string> params = 4;
}

message ModelDeploymentStatus {
  ModelDeploymentPhase phase = 1;
  string message = 2;
  int64 updated_at_ms = 3;
}

message ModelDeploymentRecord {
  string deployment_id = 1;
  uint64 revision = 2;
  int64 created_at_ms = 3;
  int64 updated_at_ms = 4;
  ModelDeploymentSpec spec = 5;
  ModelDeploymentStatus status = 6;
}

message ListModelDeploymentsRequest {
  uint32 limit = 1;
  uint32 offset = 2;
  string target_node_uuid = 3;
  string provider = 4;
}

message ListModelDeploymentsResponse {
  uint64 revision = 1;
  repeated ModelDeploymentRecord records = 2;
  uint32 total_count = 3;
}

message WatchModelDeploymentsRequest {
  uint64 since_revision = 1;
  string target_node_uuid = 2;
}

message ModelDeploymentEvent {
  uint64 revision = 1;
  repeated string upserts = 2;
  repeated string deletes = 3;
}

message WatchModelDeploymentsResponse {
  ModelDeploymentEvent event = 1;
}

message UpsertModelDeploymentRequest {
  ModelDeploymentRecord record = 1;
}

message UpsertModelDeploymentResponse {
  uint64 revision = 1;
  string deployment_id = 2;
}

message DeleteModelDeploymentRequest {
  string deployment_id = 1;
}

message DeleteModelDeploymentResponse {
  uint64 revision = 1;
}

message ReportModelDeploymentStatusRequest {
  string deployment_id = 1;
  string node_uuid = 2;
  uint64 observed_revision = 3;
  ModelDeploymentStatus status = 4;
}

message ReportModelDeploymentStatusResponse {
  bool success = 1;
}

service ModelDeploymentRegistryService {
  rpc ListModelDeployments(ListModelDeploymentsRequest) returns (ListModelDeploymentsResponse);
  rpc WatchModelDeployments(WatchModelDeploymentsRequest) returns (stream WatchModelDeploymentsResponse);
  rpc UpsertModelDeployment(UpsertModelDeploymentRequest) returns (UpsertModelDeploymentResponse);
  rpc DeleteModelDeployment(DeleteModelDeploymentRequest) returns (DeleteModelDeploymentResponse);
  rpc ReportModelDeploymentStatus(ReportModelDeploymentStatusRequest) returns (ReportModelDeploymentStatusResponse);
}
