syntax = "proto3";

package devvit.dev_portal.fetch_domain;

import "devvit/dev_portal/fetch_domain_request/fetch_domain_request.proto";
import "google/protobuf/timestamp.proto";

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

// Represents a domain's global status. UNDECIDED means the domain is not globally decided, ie only applies at the app level.
enum FetchDomainGlobalStatus {
  UNDECIDED = 0;
  ALLOWED = 1;
  DENIED = 2;
}

message FetchDomain {
  // The domain name, eg 'api.stlouisfed.org'
  string domain = 1;
  // The status of the domain, one of UNDECIDED, ALLOWED, or DENIED
  FetchDomainGlobalStatus global_status = 2;
  // When the domain was last updated (from the most recent FetchDomainRequest for this domain), eg for display as 'Updated 2h ago'.
  optional google.protobuf.Timestamp updated_at = 3;
}

message GetFetchDomainsWithStatusRequest {
  // The status of the domains to retrieve.
  FetchDomainGlobalStatus global_status = 1;
  // The page number to retrieve.
  int32 page_number = 2;
  // The number of domains to retrieve per page.
  int32 page_size = 3;
  // Optional filter: only return domains whose name contains this string (case-insensitive).
  optional string domain_filter = 4;
}

message GetFetchDomainsResponse {
  // The fetch domains to return.
  repeated FetchDomain fetch_domains = 1;
  // Indicates whether or not there is a next page of fetch domains.
  optional bool has_next_page = 2;
  // Total number of domains with the specified global status (across all pages).
  optional int32 total_count = 3;
}

// Request to add a domain to a global list (allowlist or denylist).
// If a domain already exists on the list, it will be updated with the new global status.
message AddGlobalDomainsRequest {
  // The list of domains to add to the global list.
  repeated string domains = 1;
  // The global status of the domains being added (ALLOWED or DENIED).
  FetchDomainGlobalStatus global_status = 2;
}

message RemoveGlobalDomainRequest {
  // The domain to remove from the global list, eg 'api.example.com'
  string domain = 1;
  // The global list type to remove the domain from, eg ALLOWLIST or DENYLIST.
  fetch_domain_request.GlobalListType global_list_type = 2;
}
