syntax = "proto3";

package nominal.mesh.v1;

import "buf/validate/validate.proto";
import "nominal/protos/gen/v1/alias.proto";
import "nominal/protos/gen/v1/error.proto";

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

enum ResourceType {
  RESOURCE_TYPE_UNSPECIFIED = 0;
  RESOURCE_TYPE_DATASET = 1;
}

message Link {
  // Unique identifier for this link.
  string rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LinkRid"}];
  // RID of the local resource.
  string local_resource_rid = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LocalResourceRid"}];
  // RID of the remote resource.
  string remote_resource_rid = 3 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteResourceRid"}];
  // The remote connection to use for this link.
  string remote_connection_rid = 4 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteConnectionRid"}];
  // Whether or not the link should be enabled.
  bool enabled = 5;
  // The type of resource this link is for.
  ResourceType resource_type = 6;
}

message CreateLinkRequest {
  // RID of the local resource.
  string local_resource_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LocalResourceRid"}];
  // RID of the remote resource.
  string remote_resource_rid = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteResourceRid"}];
  // The remote connection to use for this link.
  string remote_connection_rid = 3 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteConnectionRid"}];
  // Whether or not the link should be enabled.
  bool enabled = 4;
  // The type of resource this link is for.
  ResourceType resource_type = 5;
  // The workspace to register the link in. The source must belong to this workspace.
  string workspace_rid = 6 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
}

message CreateLinkResponse {}

message GetLinkRequest {
  string link_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LinkRid"}];
}

message GetLinkResponse {
  Link link = 1;
}

message UpdateLinkRequest {
  // Used to identify the link.
  string link_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LinkRid"}];
  // Optional fields to update.
  optional string remote_connection_rid = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteConnectionRid"}];
  optional bool enabled = 3;
  optional string remote_resource_rid = 4 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteResourceRid"}];
}

message UpdateLinkResponse {
  Link link = 1;
}

message DeleteLinkRequest {
  string link_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LinkRid"}];
}

message DeleteLinkResponse {}

message SearchLinksRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  int32 page_size = 2 [
    (buf.validate.field).int32.gte = 1,
    (buf.validate.field).int32.lte = 1000
  ];
  optional bool enabled = 3;
  optional ResourceType resource_type = 4;
  optional string local_resource_rid = 5 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.LocalResourceRid"}];
  optional string remote_connection_rid = 6 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.RemoteConnectionRid"}];
  optional string page_token = 7;
}

message SearchLinksResponse {
  repeated Link links = 1;
  optional string next_page_token = 2;
}

// buf:lint:ignore ENUM_ZERO_VALUE_SUFFIX
enum MeshServiceError {
  MESH_SERVICE_ERROR_LINK_NOT_FOUND = 0 [(nominal.gen.v1.error) = {
    code: "NOT_FOUND"
    message: "LinkNotFound"
  }];
  MESH_SERVICE_ERROR_LINK_ALREADY_EXISTS = 1 [(nominal.gen.v1.error) = {
    code: "ALREADY_EXISTS"
    message: "LinkAlreadyExists"
  }];
  MESH_SERVICE_ERROR_REMOTE_CONNECTION_NOT_FOUND = 2 [(nominal.gen.v1.error) = {
    code: "NOT_FOUND"
    message: "RemoteConnectionNotFound"
  }];
  MESH_SERVICE_ERROR_REMOTE_CONNECTION_ALREADY_EXISTS = 3 [(nominal.gen.v1.error) = {
    code: "ALREADY_EXISTS"
    message: "RemoteConnectionAlreadyExists"
  }];
  MESH_SERVICE_ERROR_REMOTE_CONNECTION_HAS_DEPENDENT_LINKS = 4 [(nominal.gen.v1.error) = {
    code: "FAILED_PRECONDITION"
    message: "RemoteConnectionHasDependentLinks"
  }];
  MESH_SERVICE_ERROR_INVALID_API_TOKEN = 5 [(nominal.gen.v1.error) = {
    code: "INVALID_ARGUMENT"
    message: "InvalidApiToken"
  }];
}
