syntax = "proto3";

package global.nextgen.v1;

import "global/common/v1/service_plan.proto";
import "google/api/field_behavior.proto";

service RcuQuotaService {
  rpc GetRcuQuota(GetRcuQuotaRequest) returns (RcuQuota);
  rpc CalculateMinRcu(CalculateMinRcuRequest) returns (CalculateMinRcuResponse);
  rpc ListOrgRcuQuotas(ListOrgRcuQuotasRequest) returns (ListOrgRcuQuotasResponse);
  rpc UpdateRcuQuota(UpdateRcuQuotaRequest) returns (RcuQuota);
}

message RcuQuota {
  uint64 organization_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 instance_max_rcu = 2 [(google.api.field_behavior) = OPTIONAL];
  uint64 total_max_rcu = 3 [(google.api.field_behavior) = OPTIONAL];
  float busty_ratio = 4 [
    (google.api.field_behavior) = OPTIONAL,
    deprecated = true
  ];
  common.v1.ServicePlan service_plan = 5 [(google.api.field_behavior) = OPTIONAL];
  float bursty_ratio = 6 [(google.api.field_behavior) = OPTIONAL];
  uint64 idle_resource_pool_ttl_in_hours = 7 [(google.api.field_behavior) = OPTIONAL];
  uint64 vcpus_limit_per_resource_pool = 8 [(google.api.field_behavior) = OPTIONAL];
  uint64 minimal_rcu_baseline = 9 [(google.api.field_behavior) = OPTIONAL];
  float minimal_rcu_coefficient = 10 [(google.api.field_behavior) = OPTIONAL];
  // The cooldown duration in minutes after a capacity change during which
  // scale-down of max RCU is not permitted. If 0, defaults to 720 (12 hours).
  uint64 scale_down_cooldown_minutes = 11 [(google.api.field_behavior) = OPTIONAL];
}

message GetRcuQuotaRequest {
  uint64 organization_id = 1 [(google.api.field_behavior) = REQUIRED];
  common.v1.ServicePlan service_plan = 2 [(google.api.field_behavior) = REQUIRED];
}

message CalculateMinRcuRequest {
  uint64 organization_id = 1 [(google.api.field_behavior) = REQUIRED];
  common.v1.ServicePlan service_plan = 2 [(google.api.field_behavior) = REQUIRED];
  int64 max_rcu = 3 [(google.api.field_behavior) = REQUIRED];
  string region_id = 4 [(google.api.field_behavior) = REQUIRED];
}

message CalculateMinRcuResponse {
  int64 min_rcu = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

message ListOrgRcuQuotasRequest {
  uint64 organization_id = 1 [(google.api.field_behavior) = REQUIRED];
}

message ListOrgRcuQuotasResponse {
  repeated RcuQuota rcu_quotas = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

message UpdateRcuQuotaRequest {
  RcuQuota rcu_quota = 1 [(google.api.field_behavior) = REQUIRED];
  bool validate_only = 100 [(google.api.field_behavior) = OPTIONAL];
}
