syntax = "proto3";

package api;

option go_package = "github.com/psviderski/uncloud/internal/machine/api/pb";

import "google/protobuf/empty.proto";
import "internal/machine/api/pb/common.proto";

service Docker {
  rpc CreateContainer(CreateContainerRequest) returns (CreateContainerResponse);
  rpc InspectContainer(InspectContainerRequest) returns (InspectContainerResponse);
  rpc StartContainer(StartContainerRequest) returns (google.protobuf.Empty);
  rpc StopContainer(StopContainerRequest) returns (google.protobuf.Empty);
  rpc ListContainers(ListContainersRequest) returns (ListContainersResponse);
  rpc RemoveContainer(RemoveContainerRequest) returns (google.protobuf.Empty);

  rpc PullImage(PullImageRequest) returns (stream JSONMessage);
  rpc InspectImage(InspectImageRequest) returns (InspectImageResponse);
  // InspectRemoteImage returns the image metadata for an image in a remote registry using the machine's
  // Docker auth credentials if necessary.
  rpc InspectRemoteImage(InspectRemoteImageRequest) returns (InspectRemoteImageResponse);

  rpc CreateVolume(CreateVolumeRequest) returns (CreateVolumeResponse);
  rpc ListVolumes(ListVolumesRequest) returns (ListVolumesResponse);
  rpc RemoveVolume(RemoveVolumeRequest) returns (google.protobuf.Empty);

  rpc CreateServiceContainer(CreateServiceContainerRequest) returns (CreateContainerResponse);
  rpc InspectServiceContainer(InspectContainerRequest) returns (ServiceContainer);
  rpc ListServiceContainers(ListServiceContainersRequest) returns (ListServiceContainersResponse);
  rpc RemoveServiceContainer(RemoveContainerRequest) returns (google.protobuf.Empty);
}

message CreateContainerRequest {
  // JSON serialised container.Config.
  bytes config = 1;
  // JSON serialised container.HostConfig.
  bytes host_config = 2;
  // JSON serialised network.NetworkingConfig.
  bytes network_config = 3;
  // JSON serialised ocispec.Platform.
  bytes platform = 4;
  string name = 5;
}

message CreateContainerResponse {
  // JSON serialised container.CreateResponse.
  bytes response = 1;
}

message InspectContainerRequest {
  string id = 1;
}

message InspectContainerResponse {
  // JSON serialised container.InspectResponse.
  bytes response = 1;
}

message StartContainerRequest {
  string id = 1;
  // JSON serialised container.StartOptions.
  bytes options = 2;
}

message StopContainerRequest {
  string id = 1;
  // JSON serialised container.StopOptions.
  bytes options = 2;
}

message ListContainersRequest {
  // JSON serialised container.ListOptions.
  bytes options = 1;
}

message ListContainersResponse {
  // Must contain only one repeated messages field to allow broadcasting ListContainers requests to multiple machines.
  repeated MachineContainers messages = 1;
}

message MachineContainers {
  Metadata metadata = 1;
  // JSON serialised []container.InspectResponse.
  bytes containers = 2;
}

message RemoveContainerRequest {
  string id = 1;
  // JSON serialised container.RemoveOptions.
  bytes options = 2;
}

message PullImageRequest {
  string image = 1;
  // JSON serialised image.PullOptions.
  bytes options = 2;
}

message JSONMessage {
  // JSON serialised jsonmessage.JSONMessage.
  bytes message = 1;
}

message InspectImageRequest {
  string id = 1;
}

message InspectImageResponse {
  // Must contain only one repeated messages field to allow broadcasting InspectImage requests to multiple machines.
  repeated Image messages = 1;
}

message Image {
  Metadata metadata = 1;
  // JSON serialised types.ImageInspect.
  bytes image = 2;
}

message InspectRemoteImageRequest {
  string id = 1;
}

message InspectRemoteImageResponse {
  // Must contain only one repeated messages field to allow broadcasting InspectRemoteImage requests to multiple machines.
  repeated RemoteImage messages = 1;
}

message RemoteImage {
  Metadata metadata = 1;
  // Image reference in the canonical form with the digest.
  string reference = 2;
  // Raw JSON manifest from the registry.
  bytes manifest = 3;
}

message CreateVolumeRequest {
  // JSON serialised volume.CreateOptions.
  bytes options = 1;
}

message CreateVolumeResponse {
  // JSON serialised volume.Volume.
  bytes volume = 1;
}

message ListVolumesRequest {
  // JSON serialised volume.ListOptions.
  bytes options = 1;
}

message ListVolumesResponse {
  // Must contain only one repeated messages field to allow broadcasting ListVolumes requests to multiple machines.
  repeated MachineVolumes messages = 1;
}

message MachineVolumes {
  Metadata metadata = 1;
  // JSON serialised volume.ListResponse.
  bytes response = 2;
}

message RemoveVolumeRequest {
  string id = 1;
  bool force = 2;
}

message CreateServiceContainerRequest {
  string service_id = 1;
  // JSON serialised api.ServiceSpec.
  bytes service_spec = 2;
  string container_name = 3;
}

message ServiceContainer {
  // JSON serialised container.InspectResponse.
  bytes container = 1;
  // JSON serialised api.ServiceSpec.
  bytes service_spec = 2;
}

message ListServiceContainersRequest {
  string service_id = 1;
  // JSON serialised container.ListOptions.
  bytes options = 2;
}

message ListServiceContainersResponse {
  // Must contain only one repeated messages field to allow broadcasting ListServiceContainers requests
  // to multiple machines.
  repeated MachineServiceContainers messages = 1;
}

message MachineServiceContainers {
  Metadata metadata = 1;
  repeated ServiceContainer containers = 2;
}
