syntax = "proto3";

package mesh.v1;

import "mesh/v1/management.proto";
import "mesh/v1/throttle.proto";

option go_package = "atlassian.com/bitbucket/mesh/rpc/v1";
option java_multiple_files = true;
option java_outer_classname = "ErrorProtos";
option java_package = "com.atlassian.bitbucket.mesh.rpc.v1";

/* A top-level message for encoding a specific error payload. */
message RpcError {

  oneof error_oneof {
    //ABORTED
    RpcRepositoryRepairAlreadyRunning repository_repair_already_running = 14;
    //ALREADY_EXISTS
    RpcRepositoryAlreadyExists repository_already_exists = 3;
    //FAILED_PRECONDITION
    RpcDataStoreUnavailable data_store_unavailable = 17;
    RpcForkHierarchyTooDeep fork_hierarchy_too_deep = 4;
    RpcRepositoryReadOnly repository_read_only = 8;
    RpcWrongTarget wrong_target = 20;
    //INTERNAL
    RpcConfigurationFailed configuration_failed = 10;
    RpcCreateRepositoryFailed create_repository_failed = 5;
    RpcDeleteRepositoryFailed delete_repository_failed = 12;
    RpcRepositoryRepairFailed repository_repair_failed = 13;
    RpcResetHierarchyFailed reset_hierarchy_failed = 19;
    RpcSupportZipFailed support_zip_failed = 16;
    RpcTransactionApplyError transaction_apply_error = 7;
    RpcTransactionLogError transaction_log_error = 6;
    //INVALID_ARGUMENT
    RpcInvalidPublicKey invalid_public_key = 18;
    //PERMISSION_DENIED
    //@since 1.3
    RpcPermissionDenied permission_denied = 21;
    //NOT_FOUND
    RpcNoSuchNode no_such_node = 11;
    RpcNoSuchRepository no_such_repository = 2;
    //RESOURCE_EXHAUSTED
    RpcResourceBusy resource_busy = 1;
    RpcRepositoryRepairSlotsExhausted repair_slots_exhausted = 15;
    //UNAVAILABLE
    RpcNodeUnconfigured node_unconfigured = 9;
  }
}

message RpcConfigurationFailed {
}

message RpcCreateRepositoryFailed {
  string repository = 1;
}

message RpcDataStoreUnavailable {
}

message RpcDeleteRepositoryFailed {
  string repository = 1;
}

message RpcForkHierarchyTooDeep {
  string repository = 1;
  uint32 fork_depth = 2;
}

message RpcInvalidPublicKey {
  enum Reason {
    //The specified reason could not be determined, or the Protobuf definitions do not match.
    UNKNOWN = 0;
    //The provided public key has an expiry date but was used in a context where an expiry is not allowed.
    EXPIRY_NOT_ALLOWED = 1;
    //The encoded key (DER or PKCS8) could not be parsed.
    INVALID = 2;
  }

  RpcPublicKey public_key = 1;
  Reason reason = 2;
}

message RpcNodeUnconfigured {
  //How long the Mesh node has been up, in milliseconds. This is intended to give a hint as to how long the
  //node has been waiting for configuration. A few seconds likely isn't a problem, but minutes to hours is
  //likely an indication something else has gone wrong.
  uint64 uptime = 1;
}

message RpcNoSuchNode {
  string id = 1;
}

//@since 1.3
message RpcPermissionDenied {
}

message RpcNoSuchRepository {
  string id = 1;
}

message RpcRepositoryAlreadyExists {
  string repository = 1;
  string path = 2;
}

message RpcResourceBusy {
  RpcThrottledResource resource = 1;
}

message RpcRepositoryReadOnly {
  string repository = 1;
}

message RpcRepositoryRepairAlreadyRunning {
}

message RpcRepositoryRepairFailed {
}

message RpcRepositoryRepairSlotsExhausted {
}

message RpcResetHierarchyFailed {
  string hierarchy = 1;
}

message RpcSupportZipFailed {
}

message RpcTransactionApplyError {
  string message = 1;
}

message RpcTransactionLogError {
}

message RpcWrongTarget {
  string actual_id = 1;
  string target_id = 2;
}
