// Copyright 2020 Google LLC
//
// 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 google.cloud.gaming.v1beta;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/gaming/v1beta/common.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/gaming/v1beta;gaming";

option java_multiple_files = true;
option java_package = "com.google.cloud.gaming.v1beta";
option php_namespace = "Google\\Cloud\\Gaming\\V1beta";

// Request message for GameServerDeploymentsService.ListGameServerDeployments.
message ListGameServerDeploymentsRequest {
  // Required. The parent resource name. Uses the form:
  // `projects/{project}/locations/{location}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "gameservices.googleapis.com/GameServerDeployment"
    }
  ];

  // Optional. The maximum number of items to return.  If unspecified, the
  // server will pick an appropriate default. The server may return fewer items
  // than requested. A caller should only rely on response's
  // [next_page_token][google.cloud.gaming.v1beta.ListGameServerDeploymentsResponse.next_page_token]
  // to determine if there are more GameServerDeployments left to be queried.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The next_page_token value returned from a previous List request,
  // if any.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The filter to apply to list results.
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Specifies the ordering of results following syntax at
  // https://cloud.google.com/apis/design/design_patterns#sorting_order.
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for GameServerDeploymentsService.ListGameServerDeployments.
message ListGameServerDeploymentsResponse {
  // The list of game server deployments.
  repeated GameServerDeployment game_server_deployments = 1;

  // Token to retrieve the next page of results, or empty if there are no more
  // results in the list.
  string next_page_token = 2;

  // List of locations that could not be reached.
  repeated string unreachable = 4;
}

// Request message for GameServerDeploymentsService.GetGameServerDeployment.
message GetGameServerDeploymentRequest {
  // Required. The name of the game server delpoyment to retrieve. Uses the
  // form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerDeployment"
    }
  ];
}

// Request message for
// GameServerDeploymentsService.GetGameServerDeploymentRollout.
message GetGameServerDeploymentRolloutRequest {
  // Required. The name of the game server delpoyment to retrieve. Uses the
  // form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerDeployment"
    }
  ];
}

// Request message for GameServerDeploymentsService.CreateGameServerDeployment.
message CreateGameServerDeploymentRequest {
  // Required. The parent resource name. Uses the form:
  // `projects/{project}/locations/{location}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "gameservices.googleapis.com/GameServerDeployment"
    }
  ];

  // Required. The ID of the game server delpoyment resource to be created.
  string deployment_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The game server delpoyment resource to be created.
  GameServerDeployment game_server_deployment = 3
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for GameServerDeploymentsService.DeleteGameServerDeployment.
message DeleteGameServerDeploymentRequest {
  // Required. The name of the game server delpoyment to delete. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerDeployment"
    }
  ];
}

// Request message for GameServerDeploymentsService.UpdateGameServerDeployment.
// Only allows updates for labels.
message UpdateGameServerDeploymentRequest {
  // Required. The game server delpoyment to be updated.
  // Only fields specified in update_mask are updated.
  GameServerDeployment game_server_deployment = 1
      [(google.api.field_behavior) = REQUIRED];

  // Required. Mask of fields to update. At least one path must be supplied in
  // this field. For the `FieldMask` definition, see
  //
  // https:
  // //developers.google.com/protocol-buffers
  // // /docs/reference/google.protobuf#fieldmask
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for
// GameServerDeploymentsService.UpdateGameServerRolloutDeployment.
message UpdateGameServerDeploymentRolloutRequest {
  // Required. The game server delpoyment rollout to be updated.
  // Only fields specified in update_mask are updated.
  GameServerDeploymentRollout rollout = 1
      [(google.api.field_behavior) = REQUIRED];

  // Required. Mask of fields to update. At least one path must be supplied in
  // this field. For the `FieldMask` definition, see
  //
  // https:
  // //developers.google.com/protocol-buffers
  // // /docs/reference/google.protobuf#fieldmask
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for GameServerDeploymentsService.FetchDeploymentState.
message FetchDeploymentStateRequest {
  // Required. The name of the game server delpoyment. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}`.
  string name = 1 [(google.api.field_behavior) = REQUIRED];
}

// Response message for GameServerDeploymentsService.FetchDeploymentState.
message FetchDeploymentStateResponse {
  // The game server cluster changes made by the game server deployment.
  message DeployedClusterState {
    // The name of the cluster.
    string cluster = 1;

    // The details about the Agones fleets and autoscalers created in the
    // game server cluster.
    repeated DeployedFleetDetails fleet_details = 2;
  }

  // The state of the game server deployment in each game server cluster.
  repeated DeployedClusterState cluster_state = 1;

  // List of locations that could not be reached.
  repeated string unavailable = 2;
}

// A game server deployment resource.
message GameServerDeployment {
  option (google.api.resource) = {
    type: "gameservices.googleapis.com/GameServerDeployment"
    pattern: "projects/{project}/locations/{location}/gameServerDeployments/{deployment}"
  };

  // The resource name of the game server deployment. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}`.
  // For example,
  //
  // `projects/my-project/locations/{location}/gameServerDeployments/my-deployment`.
  string name = 1;

  // Output only. The creation time.
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The last-modified time.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // The labels associated with this game server deployment. Each label is a
  // key-value pair.
  map<string, string> labels = 4;

  // ETag of the resource.
  string etag = 7;

  // Human readable description of the game server delpoyment.
  string description = 8;
}

// A game server config override.
message GameServerConfigOverride {
  // Selector chooses the game server config targets.
  oneof selector {
    // Selector for choosing applicable realms.
    RealmSelector realms_selector = 1;
  }

  // Selects the game server config and how it should be applied.
  oneof change {
    // The game server config for this override.
    string config_version = 100;
  }
}

// The game server deployment rollout which represents the desired rollout
// state.
message GameServerDeploymentRollout {
  option (google.api.resource) = {
    type: "gameservices.googleapis.com/GameServerDeploymentRollout"
    pattern: "projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout"
  };

  // The resource name of the game server deployment rollout. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout`.
  // For example,
  //
  // `projects/my-project/locations/{location}/gameServerDeployments/my-deployment/rollout`.
  string name = 1;

  // Output only. The creation time.
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The last-modified time.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // The default game server config is applied to all realms unless overridden
  // in the rollout. For example,
  //
  // `projects/my-project/locations/global/gameServerDeployments/my-game/configs/my-config`.
  string default_game_server_config = 4;

  // Contains the game server config rollout overrides. Overrides are processed
  // in the order they are listed. Once a match is found for a realm, the rest
  // of the list is not processed.
  repeated GameServerConfigOverride game_server_config_overrides = 5;

  // ETag of the resource.
  string etag = 6;
}

// Request message for PreviewGameServerDeploymentRollout.
message PreviewGameServerDeploymentRolloutRequest {
  // Required. The game server deployment rollout to be updated.
  // Only fields specified in update_mask are updated.
  GameServerDeploymentRollout rollout = 1
      [(google.api.field_behavior) = REQUIRED];

  // Optional. Mask of fields to update. At least one path must be supplied in
  // this field. For the `FieldMask` definition, see
  //
  // https:
  // //developers.google.com/protocol-buffers
  // // /docs/reference/google.protobuf#fieldmask
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The target timestamp to compute the preview. Defaults to the
  // immediately after the proposed rollout completes.
  google.protobuf.Timestamp preview_time = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Response message for PreviewGameServerDeploymentRollout.
// This has details about the Agones fleet and autoscaler to be actuated.
message PreviewGameServerDeploymentRolloutResponse {
  // Locations that could not be reached on this request.
  repeated string unavailable = 2;

  // ETag of the game server deployment.
  string etag = 3;

  // The target state.
  TargetState target_state = 4;
}
