syntax = "proto3";

package protobuf;

import "google/protobuf/timestamp.proto";
import "types.proto";

option go_package = "internal/agent/pb";

service AgentService {
  rpc ListContainers(ListContainersRequest) returns (ListContainersResponse) {}
  rpc FindContainer(FindContainerRequest) returns (FindContainerResponse) {}
  rpc StreamLogs(StreamLogsRequest) returns (stream StreamLogsResponse) {}
  rpc LogsBetweenDates(LogsBetweenDatesRequest) returns (stream StreamLogsResponse) {}
  rpc StreamRawBytes(StreamRawBytesRequest) returns (stream StreamRawBytesResponse) {}
  rpc StreamEvents(StreamEventsRequest) returns (stream StreamEventsResponse) {}
  rpc StreamStats(StreamStatsRequest) returns (stream StreamStatsResponse) {}
  rpc StreamContainerStarted(StreamContainerStartedRequest) returns (stream StreamContainerStartedResponse) {}
  rpc HostInfo(HostInfoRequest) returns (HostInfoResponse) {}
  rpc ContainerAction(ContainerActionRequest) returns (ContainerActionResponse) {}
  rpc UpdateContainer(UpdateContainerRequest) returns (stream UpdateContainerProgress) {}
  rpc ContainerExec(stream ContainerExecRequest) returns (stream ContainerExecResponse) {}
  rpc ContainerAttach(stream ContainerAttachRequest) returns (stream ContainerAttachResponse) {}
  rpc UpdateNotificationConfig(UpdateNotificationConfigRequest) returns (UpdateNotificationConfigResponse) {}
  rpc UpdateCloudConfig(UpdateCloudConfigRequest) returns (UpdateCloudConfigResponse) {}
  rpc GetNotificationStats(GetNotificationStatsRequest) returns (GetNotificationStatsResponse) {}
}

message ListContainersRequest {
  map<string, RepeatedString> filter = 1;
}

message RepeatedString {
  repeated string values = 1;
}

message ListContainersResponse {
  repeated Container containers = 1;
}

message FindContainerRequest {
  string containerId = 1;
  map<string, RepeatedString> filter = 2;
}

message FindContainerResponse {
  Container container = 1;
}

message StreamLogsRequest {
  string containerId = 1;
  google.protobuf.Timestamp since = 2;
  int32 streamTypes = 3;
}

message StreamLogsResponse {
  LogEvent event = 1;
}

message LogsBetweenDatesRequest {
  string containerId = 1;
  google.protobuf.Timestamp since = 2;
  google.protobuf.Timestamp until = 3;
  int32 streamTypes = 4;
}

message StreamRawBytesRequest {
  string containerId = 1;
  google.protobuf.Timestamp since = 2;
  google.protobuf.Timestamp until = 3;
  int32 streamTypes = 4;
}
message StreamRawBytesResponse {
  bytes data = 1;
}

message StreamEventsRequest {}
message StreamEventsResponse {
  ContainerEvent event = 1;
}

message StreamStatsRequest {}
message StreamStatsResponse {
  ContainerStat stat = 1;
}

message HostInfoRequest {}

message HostInfoResponse {
  Host host = 1;
}

message StreamContainerStartedRequest {}
message StreamContainerStartedResponse {
  Container container = 1;
}

message ContainerActionRequest {
  string containerId = 1;
  ContainerAction action = 2;
}

message ContainerActionResponse {}

message UpdateContainerRequest {
  string containerId = 1;
}

message UpdateContainerProgress {
  string status = 1;
  string layer = 2;
  int64 current = 3;
  int64 total = 4;
  string error = 5;
}

message ContainerExecRequest {
  string containerId = 1;
  repeated string command = 2;
  oneof payload {
    bytes stdin = 3;
    ResizePayload resize = 4;
  }
}

message ResizePayload {
  uint32 width = 1;
  uint32 height = 2;
}

message ContainerExecResponse {
  bytes stdout = 1;
}

message ContainerAttachRequest {
  string containerId = 1;
  oneof payload {
    bytes stdin = 2;
    ResizePayload resize = 3;
  }
}

message ContainerAttachResponse {
  bytes stdout = 1;
}

message UpdateNotificationConfigRequest {
  repeated NotificationSubscription subscriptions = 1;
  repeated NotificationDispatcher dispatchers = 2;
}

message UpdateNotificationConfigResponse {}

message UpdateCloudConfigRequest {
  NotificationCloudConfig cloudConfig = 1;
}

message UpdateCloudConfigResponse {}

message GetNotificationStatsRequest {}

message GetNotificationStatsResponse {
  repeated NotificationSubscriptionStats stats = 1;
}
