syntax = "proto3";
package base.v1;

option go_package = "github.com/Permify/permify/pkg/pb/base/v1";

enum ErrorCode {
  ERROR_CODE_UNSPECIFIED = 0;

  // authn
  ERROR_CODE_MISSING_BEARER_TOKEN = 1001;
  ERROR_CODE_UNAUTHENTICATED = 1002;
  ERROR_CODE_MISSING_TENANT_ID = 1003;
  ERROR_CODE_INVALID_AUDIENCE = 1004;
  ERROR_CODE_INVALID_CLAIMS = 1005;
  ERROR_CODE_INVALID_ISSUER = 1006;
  ERROR_CODE_INVALID_BEARER_TOKEN = 1007;

  // validation
  ERROR_CODE_VALIDATION = 2000;
  ERROR_CODE_UNDEFINED_CHILD_TYPE = 2002;
  ERROR_CODE_UNDEFINED_CHILD_KIND = 2003;
  ERROR_CODE_UNDEFINED_RELATION_REFERENCE = 2006;
  ERROR_CODE_NOT_SUPPORTED_RELATION_WALK = 2007;
  ERROR_CODE_ENTITY_AND_SUBJECT_CANNOT_BE_EQUAL = 2008;
  ERROR_CODE_DEPTH_NOT_ENOUGH = 2009;
  ERROR_CODE_RELATION_REFERENCE_NOT_FOUND_IN_ENTITY_REFERENCES = 2010;
  ERROR_CODE_RELATION_REFERENCE_MUST_HAVE_ONE_ENTITY_REFERENCE = 2011;
  ERROR_CODE_DUPLICATED_ENTITY_REFERENCE = 2012;
  ERROR_CODE_DUPLICATED_RELATION_REFERENCE = 2013;
  ERROR_CODE_DUPLICATED_PERMISSION_REFERENCE = 2014;
  ERROR_CODE_SCHEMA_PARSE = 2015;
  ERROR_CODE_SCHEMA_COMPILE = 2016;
  ERROR_CODE_SUBJECT_RELATION_MUST_BE_EMPTY = 2017;
  ERROR_CODE_SUBJECT_RELATION_CANNOT_BE_EMPTY = 2018;
  ERROR_CODE_SCHEMA_MUST_HAVE_USER_ENTITY_DEFINITION = 2019;
  ERROR_CODE_UNIQUE_CONSTRAINT = 2020;
  ERROR_CODE_INVALID_CONTINUOUS_TOKEN = 2021;
  ERROR_CODE_INVALID_KEY = 2022;
  ERROR_CODE_ENTITY_TYPE_REQUIRED = 2023;
  ERROR_CODE_NO_ENTITY_REFERENCES_FOUND_IN_SCHEMA = 2024;
  ERROR_CODE_INVALID_ARGUMENT = 2025;
  ERROR_CODE_INVALID_RULE_REFERENCE = 2026;
  ERROR_CODE_NOT_SUPPORTED_WALK = 2027;
  ERROR_CODE_MISSING_ARGUMENT = 2028;
  ERROR_CODE_ALREADY_EXIST = 2029;
  ERROR_CODE_MAX_DATA_PER_WRITE_EXCEEDED = 2030;

  // not found
  ERROR_CODE_NOT_FOUND = 4000;
  ERROR_CODE_ENTITY_TYPE_NOT_FOUND = 4001;
  ERROR_CODE_PERMISSION_NOT_FOUND = 4002;
  ERROR_CODE_SCHEMA_NOT_FOUND = 4003;
  ERROR_CODE_SUBJECT_TYPE_NOT_FOUND = 4004;
  ERROR_CODE_ENTITY_DEFINITION_NOT_FOUND = 4005;
  ERROR_CODE_PERMISSION_DEFINITION_NOT_FOUND = 4006;
  ERROR_CODE_RELATION_DEFINITION_NOT_FOUND = 4007;
  ERROR_CODE_RECORD_NOT_FOUND = 4008;
  ERROR_CODE_TENANT_NOT_FOUND = 4009;
  ERROR_CODE_ATTRIBUTE_DEFINITION_NOT_FOUND = 4010;
  ERROR_CODE_ATTRIBUTE_TYPE_MISMATCH = 4011;
  ERROR_CODE_BUNDLE_NOT_FOUND = 4012;
  ERROR_CODE_RULE_DEFINITION_NOT_FOUND = 4013;
  ERROR_CODE_ENTITY_STATEMENT_NOT_FOUND = 4014;
  ERROR_CODE_REFERENCE_NOT_FOUND = 4015;

  // internal
  ERROR_CODE_INTERNAL = 5000;
  ERROR_CODE_CANCELLED = 5001;
  ERROR_CODE_SQL_BUILDER = 5002;
  ERROR_CODE_CIRCUIT_BREAKER = 5003;
  ERROR_CODE_EXECUTION = 5005;
  ERROR_CODE_SCAN = 5006;
  ERROR_CODE_MIGRATION = 5007;
  ERROR_CODE_TYPE_CONVERSATION = 5008;
  ERROR_CODE_ERROR_MAX_RETRIES = 5009;
  ERROR_CODE_ROLLBACK = 5010;
  ERROR_CODE_EXCLUSION_REQUIRES_MORE_THAN_ONE_FUNCTION = 5011;
  ERROR_CODE_NOT_IMPLEMENTED = 5012;
  ERROR_CODE_DATASTORE = 5013;
  ERROR_CODE_UNKNOWN_STATEMENT_TYPE = 5014;
  ERROR_CODE_UNKNOWN_REFERENCE_TYPE = 5015;
  ERROR_CODE_CANNOT_CONVERT_TO_ENTITY_STATEMENT = 5016;
  ERROR_CODE_CANNOT_CONVERT_TO_RELATION_STATEMENT = 5017;
  ERROR_CODE_CANNOT_CONVERT_TO_ATTRIBUTE_STATEMENT = 5018;
  ERROR_CODE_SERIALIZATION = 5019;
}

// ErrorResponse
message ErrorResponse {
  ErrorCode code = 1;
  string message = 2;
}