syntax = "proto3";

package coda.admin.v1;

option java_package = "coda.admin.v1";
option java_outer_classname = "CacheProto";

service CacheService {
  // Read cache entries without modifying them.
  rpc ListCache(ListCacheRequest) returns (ListCacheResponse);

  // Read and delete specific cache entries.
  rpc BustCache(BustCacheRequest) returns (BustCacheResponse);

  // Delete all cache entries matching a type pattern.
  rpc BludgeonCache(BludgeonCacheRequest) returns (BludgeonCacheResponse);
}

// ─── ListCache ──────────────────────────────────────────────────────

message ListCacheRequest {
  repeated string keys = 1;
}

message CacheItem {
  string key = 1;
  string value = 2;
  bool found = 3;
}

message ListCacheResponse {
  repeated CacheItem items = 1;
}

// ─── BustCache ──────────────────────────────────────────────────────

message BustCacheRequest {
  repeated string keys = 1;
}

message BustCacheItem {
  string key = 1;
  string value = 2;
  bool deleted = 3;
}

message BustCacheResponse {
  repeated BustCacheItem items = 1;
}

// ─── BludgeonCache ──────────────────────────────────────────────────

enum CacheType {
  CACHE_TYPE_UNSPECIFIED = 0;
  CACHE_TYPE_EFFECTIVE_PERMISSIONS = 1;
  CACHE_TYPE_DENY_OVERRIDES = 2;
  CACHE_TYPE_ROLE_PERMISSIONS = 3;
  CACHE_TYPE_PLAN_FEATURES = 4;
  CACHE_TYPE_TENANT_STATUS = 5;
  CACHE_TYPE_USER_STATUS = 6;
  CACHE_TYPE_SUPER_ADMIN = 7;
  CACHE_TYPE_GROUP_MEMBERSHIP = 8;
  CACHE_TYPE_DPA_VALID = 9;
  CACHE_TYPE_POLICY_CONDITIONS = 10;
  CACHE_TYPE_ALL = 99;
}

message BludgeonCacheRequest {
  CacheType cache_type = 1;
  // Must be true to actually delete. Default (false) = dry run.
  bool confirm_delete = 2;
}

message BludgeonCacheResponse {
  int32 total_keys_before = 1;
  int32 keys_affected = 2;
  bool deleted = 3;
}
