syntax = "proto3";

package devvit.gateway.utils.v1alpha;

import "devvit/dev_portal/fetch_domain_request/fetch_domain_request.proto";

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/utilities";

message AccessKeyPurgeRequest {
  string user_id = 1; // the t2_ user id
  bool include_refresh = 2; // also purge the refresh key
}

message InstallationsPurgeRequest {
  string subreddit = 1; // t5 subreddit id
}

message InstallationPurgeRequest {
  string installation_id = 1;
}

message AppVersionPurgeRequest {
  string app_version_id = 1;
}

message AppPurgeRequest {
  string app_id = 1;
  string app_slug = 2;
}

message AppVersionPublishStatusPurgeRequest {
  string app_version_id = 1;
}

enum CurationType {
  CURATION_TYPE_UNSPECIFIED = 0;
  CURATION_TYPE_NEW = 1;
  CURATION_TYPE_POPULAR = 2;
}

// Purge request for curated games cache.
message CuratedGamesPurgeRequest {
  CurationType curation_type = 1; // curation type to purge (example: "NEW" or "POPULAR")
}

message PurgeAllRequest {
  // Purge all cache entries of the specified type
  enum CacheType {
    UNSPECIFIED = 0;
    // devvit-ecosystem cache types
    INSTALLATION = 1;
    SUBREDDIT_APP_INSTALLS = 2;
    APP = 3;
    APP_BY_ID = 4;
    APP_PUBLISH_REQUEST = 5;
    APP_DOMAINS = 6;
    GLOBAL_DOMAINS = 7;
    // devvit-runtime cache types
    POST = 8;
    POST_RENDER = 9;
    POSTS_BY_INSTALLATION = 10;
    CONTEXT_ACTIONS = 11;
    APP_PERMISSIONS = 12;
    // other cache types
    DRAWER = 13;
    TOP_CUSTOM_POSTS = 14;
    APP_HEALTH = 15;
    APP_WITH_CATEGORIES = 16;
  }

  CacheType cache_type = 1;
}

message PurgeResult {
  int64 count = 1; // Number of items purged
}

message CacheContextActionsRequest {
  string installation_id = 1;
}

service CacheUtils {
  // Temporary method for fetching context actions and storing/caching them in the Runtime DB.
  // This is for a single-use backfill and can be removed afterwards.
  // TODO(gunsch): delete when finished.
  rpc CacheContextActionsInRuntimeDb(CacheContextActionsRequest) returns (PurgeResult);

  rpc PurgeAccessKey(AccessKeyPurgeRequest) returns (PurgeResult);
  rpc PurgeInstallations(InstallationsPurgeRequest) returns (PurgeResult);
  rpc PurgeInstallation(InstallationPurgeRequest) returns (PurgeResult);
  rpc PurgeAppVersion(AppVersionPurgeRequest) returns (PurgeResult);
  rpc PurgeApp(AppPurgeRequest) returns (PurgeResult);
  rpc PurgeAppVersionPublishStatus(AppVersionPublishStatusPurgeRequest) returns (PurgeResult);
  rpc PurgeCuratedGames(CuratedGamesPurgeRequest) returns (PurgeResult);
  rpc PurgeAll(PurgeAllRequest) returns (PurgeResult);
  // Purges global domains cache then repopulates from DB. Use after adding or removing global domains.
  rpc RefreshGlobalDomains(RefreshGlobalDomainsRequest) returns (PurgeResult);
}

message RefreshGlobalDomainsRequest {
  // The global list type to refresh (ALLOWLIST or DENYLIST).
  // If not specified, both allowlist and denylist will be refreshed.
  optional devvit.dev_portal.fetch_domain_request.GlobalListType global_list_type = 1;
}

message AcceptInviteRequest {
  string subreddit_name = 1;
  string app_account_id = 2;
}

message AcceptInviteResponse {}

service ModInviteUtils {
  rpc AcceptInvite(AcceptInviteRequest) returns (AcceptInviteResponse);
}
