// Copyright 2018 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package istio.mixer.adapter.model.v1beta1;

option go_package="istio.io/api/mixer/adapter/model/v1beta1";

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";

option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = false;
option (gogoproto.gostring_all) = false;

// Expresses the quota allocation request.
message QuotaRequest {
  // parameters for a quota allocation
  message QuotaParams {
    // Amount of quota to allocate
    int64 amount = 1;

    // When true, supports returning less quota than what was requested.
    bool best_effort = 2;
  }

  // The individual quotas to allocate
  map<string, QuotaParams> quotas = 1 [(gogoproto.nullable) = false];
}

// Expresses the result of multiple quota allocations.
message QuotaResult {
  // Expresses the result of a quota allocation.
  message Result {
    // The amount of time for which this result can be considered valid.
    google.protobuf.Duration valid_duration = 2 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];

    // The amount of granted quota. When `QuotaParams.best_effort` is true, this will be >= 0.
    // If `QuotaParams.best_effort` is false, this will be either 0 or >= `QuotaParams.amount`.
    int64 granted_amount = 3;
  }

  // The resulting quota, one entry per requested quota.
  map<string, Result> quotas = 1 [(gogoproto.nullable) = false];
}
