syntax = "proto3";

package nominal.mesh.v1;

import "google/api/annotations.proto";
import "nominal/protos/direct_channel_writer/v2/direct_nominal_channel_writer.proto";
import "nominal/protos/mesh/v1/links.proto";
import "nominal/protos/mesh/v1/remote_connections.proto";

option java_multiple_files = true;
option java_package = "io.nominal.mesh.v1";

// This is the proto that is sent to remote environments to request mesh operations.
message MeshRequest {
  oneof request {
    DataStreamRequest data_stream = 1;
    FileIngestRequest file_ingest = 2;
  }
}

message MeshResponse {}
message DataStreamRequest {
  repeated nominal.direct_channel_writer.v2.InternalWriteBatchesRequest write_batches_request = 1;
}

message FileIngestRequest {
  // JSON-serialized conjure IngestRequest (io.nominal.ingest.api.IngestRequest).
  // The receiving side deserializes this using a conjure ObjectMapper.
  bytes ingest_request = 1;
}

message HealthCheckRequest {}

message HealthCheckResponse {}

// Manages mesh links between local and remote environments.
service MeshService {
  // Core Mesh operations.
  // ------------------------------------------------------------------------------------------------------------
  // Used to mesh resources between stacks.
  rpc Mesh(MeshRequest) returns (MeshResponse) {
    option (google.api.http) = {
      post: "/mesh/v1/mesh"
      body: "*"
    };
  }
  // Used to determine the health of a stack and its availability for meshing.
  rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse) {
    option (google.api.http) = {get: "/mesh/v1/health"};
  }

  // Link operations.
  // ------------------------------------------------------------------------------------------------------------
  // Creates a link which allows the specified resource to be synced between mesh environments.
  // Throws MESH_SERVICE_ERROR_LINK_ALREADY_EXISTS if a link already exists.
  rpc CreateLink(CreateLinkRequest) returns (CreateLinkResponse) {
    option (google.api.http) = {
      post: "/mesh/v1/links"
      body: "*"
    };
  }

  // Retrieves a link for the requested resource, throwing MESH_SERVICE_ERROR_LINK_NOT_FOUND if there is no link.
  rpc GetLink(GetLinkRequest) returns (GetLinkResponse) {
    option (google.api.http) = {get: "/mesh/v1/links/{link_rid}"};
  }

  // Updates a link for the requested resource, throwing MESH_SERVICE_ERROR_LINK_NOT_FOUND if there is no link.
  rpc UpdateLink(UpdateLinkRequest) returns (UpdateLinkResponse) {
    option (google.api.http) = {
      put: "/mesh/v1/links/{link_rid}"
      body: "*"
    };
  }

  // Deletes a link for the specified resource.
  rpc DeleteLink(DeleteLinkRequest) returns (DeleteLinkResponse) {
    option (google.api.http) = {delete: "/mesh/v1/links/{link_rid}"};
  }

  // Searches for links with optional filters and pagination.
  rpc SearchLinks(SearchLinksRequest) returns (SearchLinksResponse) {
    option (google.api.http) = {
      post: "/mesh/v1/links/search"
      body: "*"
    };
  }

  // Remote Connection operations.
  // ------------------------------------------------------------------------------------------------------------
  // Creates a remote connection for mesh links.
  // Throws MESH_SERVICE_ERROR_REMOTE_CONNECTION_ALREADY_EXISTS if a remote connection with the same name already exists.
  rpc CreateRemoteConnection(CreateRemoteConnectionRequest) returns (CreateRemoteConnectionResponse) {
    option (google.api.http) = {
      post: "/mesh/v1/remote-connections"
      body: "*"
    };
  }

  // Retrieves a remote connection by RID.
  // Throws MESH_SERVICE_ERROR_REMOTE_CONNECTION_NOT_FOUND if there is no remote connection.
  rpc GetRemoteConnection(GetRemoteConnectionRequest) returns (GetRemoteConnectionResponse) {
    option (google.api.http) = {get: "/mesh/v1/remote-connections/{remote_connection_rid}"};
  }

  // Updates a remote connection by RID.
  // Throws MESH_SERVICE_ERROR_REMOTE_CONNECTION_NOT_FOUND if there is no remote connection.
  rpc UpdateRemoteConnection(UpdateRemoteConnectionRequest) returns (UpdateRemoteConnectionResponse) {
    option (google.api.http) = {
      put: "/mesh/v1/remote-connections/{remote_connection_rid}"
      body: "*"
    };
  }

  // Deletes a remote connection by RID.
  rpc DeleteRemoteConnection(DeleteRemoteConnectionRequest) returns (DeleteRemoteConnectionResponse) {
    option (google.api.http) = {delete: "/mesh/v1/remote-connections/{remote_connection_rid}"};
  }

  // Lists all remote connections.
  rpc ListRemoteConnections(ListRemoteConnectionsRequest) returns (ListRemoteConnectionsResponse) {
    option (google.api.http) = {get: "/mesh/v1/remote-connections"};
  }
}
