# bex-api's managed Key Value (Valkey) surface, Render dashboard-shaped
# (backend/internal/keyvalue/graphql.go, docs/ADR006-bex-api.md §Managed Key Value,
# docs/ADR021-keyvalue-management.md). Render's dashboard GraphQL noun is `keyValue`,
# matching bex's own KeyValue CRD (the postgres feature's `database` noun is the
# sibling precedent). `status` is Render's keyValueStatus enum
# (available/unavailable/creating); `suspended` is the string enum shared with
# services/databases. There is no separate detail-only field set — `keyValue(id)`
# returns the same shape as the list (unlike Database, whose detail query adds
# databaseName/databaseUser/highAvailabilityEnabled).

query KeyValues {
  keyValues {
    id
    name
    plan
    version
    status
    suspended
    createdAt
    externalHost
    public
  }
}

query KeyValue($id: String!) {
  keyValue(id: $id) {
    id
    name
    plan
    version
    status
    suspended
    createdAt
    externalHost
    public
  }
}

# The one place the connection strings (which embed the password) are surfaced
# (docs/ADR021-keyvalue-management.md): fetched on demand from the detail page's
# "Reveal", never in the bulk list and never on page load. Returns the
# Render-shaped `KeyValueConnectionInfo` — no standalone password field, unlike
# Postgres, since Valkey's password lives inside the `redis://` URI itself.
query KeyValueConnectionInfo($id: String!) {
  keyValueConnectionInfo(id: $id) {
    internalConnectionString
    externalConnectionString
    cliCommand
  }
}

# The create dialog's plan-picker source (w5/m12): the shared lego/types/tiers
# Valkey family, read live — never a hardcoded ladder in the frontend.
query KeyValueInstanceTypes {
  keyValueInstanceTypes {
    id
    name
    cpu
    memory
    storageGB
  }
}

# The external-endpoint CIDR allowlist (Render's Networking control), the
# managed-Postgres databaseIpAllowList sibling. Empty => open to all source IPs;
# only meaningful when the store is public. Read/edited by the detail page's
# Networking section.
query KeyValueIpAllowList($id: String!) {
  keyValueIpAllowList(id: $id)
}

mutation CreateKeyValue(
  $name: String!
  $plan: String
  $version: String
  $storageGB: Int
  $public: Boolean
) {
  createKeyValue(
    name: $name
    plan: $plan
    version: $version
    storageGB: $storageGB
    public: $public
  ) {
    id
    name
    plan
    status
  }
}

mutation SetKeyValueIpAllowList($id: String!, $cidrs: [String]) {
  setKeyValueIpAllowList(id: $id, cidrs: $cidrs) {
    id
    ipAllowList
  }
}

mutation DeleteKeyValue($id: String!) {
  deleteKeyValue(id: $id)
}

mutation SuspendKeyValue($id: String!) {
  suspendKeyValue(id: $id) {
    id
    suspended
  }
}

mutation ResumeKeyValue($id: String!) {
  resumeKeyValue(id: $id) {
    id
    suspended
  }
}
