// Copyright 2021 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.v1;

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

option go_package = "cloud.google.com/go/gaming/apiv1/gamingpb;gamingpb";
option java_multiple_files = true;
option java_package = "com.google.cloud.gaming.v1";

// A view for GameServerCluster objects.
enum GameServerClusterView {
  // The default / unset value.
  // The API will default to the BASIC view.
  GAME_SERVER_CLUSTER_VIEW_UNSPECIFIED = 0;

  // Include basic information of a GameServerCluster resource and omit
  // `cluster_state`. This is the default value (for ListGameServerClusters,
  // GetGameServerCluster and PreviewCreateGameServerCluster).
  BASIC = 1;

  // Include everything.
  FULL = 2;
}

// Request message for GameServerClustersService.ListGameServerClusters.
message ListGameServerClustersRequest {
  // Required. The parent resource name, in the following form:
  // "projects/{project}/locations/{location}/realms/{realm}".
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];

  // 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.v1.ListGameServerClustersResponse.next_page_token] to
  // determine if there are more GameServerClusters 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];

  // Optional. View for the returned GameServerCluster objects. When `FULL` is
  // specified, the `cluster_state` field is also returned in the
  // GameServerCluster object, which includes the state of the referenced
  // Kubernetes cluster such as versions and provider info. The default/unset
  // value is GAME_SERVER_CLUSTER_VIEW_UNSPECIFIED, same as BASIC, which does
  // not return the `cluster_state` field.
  GameServerClusterView view = 6 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for GameServerClustersService.ListGameServerClusters.
message ListGameServerClustersResponse {
  // The list of game server clusters.
  repeated GameServerCluster game_server_clusters = 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 GameServerClustersService.GetGameServerCluster.
message GetGameServerClusterRequest {
  // Required. The name of the game server cluster to retrieve, in the following form:
  // `projects/{project}/locations/{location}/realms/{realm-id}/gameServerClusters/{cluster}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];

  // Optional. View for the returned GameServerCluster objects. When `FULL` is
  // specified, the `cluster_state` field is also returned in the
  // GameServerCluster object, which includes the state of the referenced
  // Kubernetes cluster such as versions and provider info. The default/unset
  // value is GAME_SERVER_CLUSTER_VIEW_UNSPECIFIED, same as BASIC, which does
  // not return the `cluster_state` field.
  GameServerClusterView view = 6 [(google.api.field_behavior) = OPTIONAL];
}

// Request message for GameServerClustersService.CreateGameServerCluster.
message CreateGameServerClusterRequest {
  // Required. The parent resource name, in the following form:
  // `projects/{project}/locations/{location}/realms/{realm-id}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];

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

  // Required. The game server cluster resource to be created.
  GameServerCluster game_server_cluster = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request message for GameServerClustersService.PreviewCreateGameServerCluster.
message PreviewCreateGameServerClusterRequest {
  // Required. The parent resource name, in the following form:
  // `projects/{project}/locations/{location}/realms/{realm}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];

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

  // Required. The game server cluster resource to be created.
  GameServerCluster game_server_cluster = 3 [(google.api.field_behavior) = REQUIRED];

  // Optional. The target timestamp to compute the preview.
  google.protobuf.Timestamp preview_time = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. This field is deprecated, preview will always return
  // KubernetesClusterState.
  GameServerClusterView view = 6 [
    deprecated = true,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Response message for
// GameServerClustersService.PreviewCreateGameServerCluster.
message PreviewCreateGameServerClusterResponse {
  // The ETag of the game server cluster.
  string etag = 2;

  // The target state.
  TargetState target_state = 3;

  // Output only. The state of the Kubernetes cluster in preview, this will be available if
  // 'view' is set to `FULL` in the relevant List/Get/Preview request.
  KubernetesClusterState cluster_state = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for GameServerClustersService.DeleteGameServerCluster.
message DeleteGameServerClusterRequest {
  // Required. The name of the game server cluster to delete, in the following form:
  // `projects/{project}/locations/{location}/gameServerClusters/{cluster}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];
}

// Request message for GameServerClustersService.PreviewDeleteGameServerCluster.
message PreviewDeleteGameServerClusterRequest {
  // Required. The name of the game server cluster to delete, in the following form:
  // `projects/{project}/locations/{location}/gameServerClusters/{cluster}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "gameservices.googleapis.com/GameServerCluster"
    }
  ];

  // Optional. The target timestamp to compute the preview.
  google.protobuf.Timestamp preview_time = 2 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for
// GameServerClustersService.PreviewDeleteGameServerCluster.
message PreviewDeleteGameServerClusterResponse {
  // The ETag of the game server cluster.
  string etag = 2;

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

// Request message for GameServerClustersService.UpdateGameServerCluster.
message UpdateGameServerClusterRequest {
  // Required. The game server cluster to be updated.
  // Only fields specified in update_mask are updated.
  GameServerCluster game_server_cluster = 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 GameServerClustersService.UpdateGameServerCluster.
message PreviewUpdateGameServerClusterRequest {
  // Required. The game server cluster to be updated.
  // Only fields specified in update_mask are updated.
  GameServerCluster game_server_cluster = 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];

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

// Response message for GameServerClustersService.PreviewUpdateGameServerCluster
message PreviewUpdateGameServerClusterResponse {
  // The ETag of the game server cluster.
  string etag = 2;

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

// The game server cluster connection information.
message GameServerClusterConnectionInfo {
  // The location of the Kubernetes cluster.
  oneof cluster_reference {
    // Reference to the GKE cluster where the game servers are installed.
    GkeClusterReference gke_cluster_reference = 7;
  }

  // Namespace designated on the game server cluster where the Agones game
  // server instances will be created. Existence of the namespace will be
  // validated during creation.
  string namespace = 5;
}

// A reference to a GKE cluster.
message GkeClusterReference {
  // The full or partial name of a GKE cluster, using one of the following
  // forms:
  //  * `projects/{project}/locations/{location}/clusters/{cluster}`
  //  * `locations/{location}/clusters/{cluster}`
  //  * `{cluster}`
  // If project and location are not specified, the project and location of the
  // GameServerCluster resource are used to generate the full name of the
  // GKE cluster.
  string cluster = 1;
}

// A game server cluster resource.
message GameServerCluster {
  option (google.api.resource) = {
    type: "gameservices.googleapis.com/GameServerCluster"
    pattern: "projects/{project}/locations/{location}/realms/{realm}/gameServerClusters/{cluster}"
  };

  // Required. The resource name of the game server cluster, in the following form:
  // `projects/{project}/locations/{location}/realms/{realm}/gameServerClusters/{cluster}`.
  // For example,
  // `projects/my-project/locations/{location}/realms/zanzibar/gameServerClusters/my-onprem-cluster`.
  string name = 1 [(google.api.field_behavior) = REQUIRED];

  // 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 cluster. Each label is a
  // key-value pair.
  map<string, string> labels = 4;

  // The game server cluster connection information. This information is used to
  // manage game server clusters.
  GameServerClusterConnectionInfo connection_info = 5;

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

  // Human readable description of the cluster.
  string description = 7;

  // Output only. The state of the Kubernetes cluster, this will be available if
  // 'view' is set to `FULL` in the relevant List/Get/Preview request.
  KubernetesClusterState cluster_state = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The state of the Kubernetes cluster.
message KubernetesClusterState {
  // The state of the installed versions of Agones/Kubernetes. See also
  // https://cloud.google.com/game-servers/docs/versions-and-upgrades.
  enum InstallationState {
    // The default value. This value is used if the state is omitted.
    INSTALLATION_STATE_UNSPECIFIED = 0;

    // The combination of Agones and Kubernetes versions is supported by Google
    // Cloud Game Servers.
    AGONES_KUBERNETES_VERSION_SUPPORTED = 1;

    // The installed version of Agones is not supported by Google Cloud Game
    // Servers.
    AGONES_VERSION_UNSUPPORTED = 2;

    // The installed version of Agones is supported by Google Cloud Game
    // Servers, but the installed version of Kubernetes is not recommended or
    // supported by the version of Agones.
    AGONES_KUBERNETES_VERSION_UNSUPPORTED = 3;

    // The installed version of Agones is not recognized because the Agones
    // controller's image name does not have a version string reported as
    // {major}.{minor}(.{patch}).
    AGONES_VERSION_UNRECOGNIZED = 4;

    // The server version of Kubernetes cluster is not recognized because the
    // API server didn't return parsable version info on path/version.
    KUBERNETES_VERSION_UNRECOGNIZED = 5;

    // Failed to read or verify the version of Agones or Kubernetes. See
    // version_installed_error_message for details.
    VERSION_VERIFICATION_FAILED = 6;

    // Agones is not installed.
    AGONES_NOT_INSTALLED = 7;
  }

  // Output only. The version of Agones currently installed in the registered Kubernetes
  // cluster.
  string agones_version_installed = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The version of Kubernetes that is currently used in the registered
  // Kubernetes cluster (as detected by the Cloud Game Servers service).
  string kubernetes_version_installed = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The state for the installed versions of Agones/Kubernetes.
  InstallationState installation_state = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The detailed error message for the installed versions of Agones/Kubernetes.
  string version_installed_error_message = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The cloud provider type reported by the first node's providerID in the list
  // of nodes on the Kubernetes endpoint. On Kubernetes platforms that support
  // zero-node clusters (like GKE-on-GCP), the provider type will be empty.
  string provider = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The version of Agones that is targeted to be installed in the cluster.
  string agones_version_targeted = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
}
