//  Copyright 2026 Google LLC
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

syntax = "proto3";

package atelet;

option go_package = "github.com/agent-substrate/substrate/proto/ateletpb";

service AteomHerder {
  // Run tells atelet to create a new containerized workload from scratch on an
  // ateom.
  rpc Run(RunRequest) returns (RunResponse) {}

  // Checkpoint tells atelet to save the current state of the workload on an
  // ateom to object storage, and then completely reset the ateom to a blank state
  // (back to "available" state.)
  rpc Checkpoint(CheckpointRequest) returns (CheckpointResponse) {}

  // Restore restores a workload from checkpoint onto an ateom.
  rpc Restore(RestoreRequest) returns (RestoreResponse) {}
}

message RunRequest {
  string target_ateom_namespace = 1;
  string target_ateom_name      = 2;

  string actor_template_namespace = 3;
  string actor_template_name      = 4;
  string actor_id                 = 5;

  RunscConfig runsc = 8;

  WorkloadSpec spec = 7;
}

message GCPAuthenticationConfig {
  bool use = 1;
}

message AuthenticationConfig {
  GCPAuthenticationConfig gcp = 1;
}

message RunscPlatformConfig {
  // Check the downloaded binary against this hash.  Also used for naming the
  // downloaded file to prevent collisions.
  string sha256_hash = 1;

  // gs:// URL to download the runsc binary.
  string url = 2;
}

message RunscConfig {
  RunscPlatformConfig amd64 = 1;
  RunscPlatformConfig arm64 = 2;

  // How should atelet authenticate to fetch the runsc binary?
  AuthenticationConfig authentication = 3;
}

// WorkloadSpec parallels Pod, but with far fewer configurable fields.
message WorkloadSpec {
  repeated Container containers  = 1;
  string             pause_image = 2;
}

message Container {
  string            name    = 1;
  string            image   = 2;
  repeated string   command = 3;
  repeated EnvEntry env     = 4;
}

message EnvEntry {
  string name  = 1;
  string value = 2;
}

message RunResponse {
}

message CheckpointRequest {
  string target_ateom_namespace = 1;
  string target_ateom_name      = 2;

  string actor_template_namespace = 3;
  string actor_template_name      = 4;
  string actor_id                 = 5;

  RunscConfig runsc = 6;

  WorkloadSpec spec = 7;

  // An object storage URI prefix below which the checkpoint data will be
  // stored.
  //
  // The structure of the checkpoint should generally be treated as opaque. For
  // gVisor, the checkpoint consists of a checkpoint.img file that contains the
  // memory, sentry state, and filesystem deltas.  ateom will write additional
  // files to store the WorkloadSpec, which must be reassembled before gVisor
  // can restore a checkpoint.
  //
  // For example: "gs://bucket/actors/1234/snapshots/5678/"
  string snapshot_uri_prefix = 8;
}

message CheckpointResponse {

}

message RestoreRequest {
  string target_ateom_namespace = 1;
  string target_ateom_name      = 2;

  string actor_template_namespace = 3;
  string actor_template_name      = 4;
  string actor_id                 = 5;

  RunscConfig runsc = 6;

  WorkloadSpec spec = 7;

  // The object storage URI prefix of the snapshot to restore.
  string snapshot_uri_prefix = 8;
}

message RestoreResponse {

}
