// 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/protobuf/duration.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";

// Represents the metadata of the long-running operation.
message OperationMetadata {
  // Output only. The time the operation was created.
  google.protobuf.Timestamp create_time = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The time the operation finished running.
  google.protobuf.Timestamp end_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Server-defined resource path for the target of the operation.
  string target = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Name of the verb executed by the operation.
  string verb = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Human-readable status of the operation, if any.
  string status_message = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Identifies whether the user has requested cancellation
  // of the operation. Operations that have successfully been cancelled
  // have [Operation.error][] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`.
  bool requested_cancellation = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. API version used to start the operation.
  string api_version = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. List of Locations that could not be reached.
  repeated string unreachable = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Operation status for Game Services API operations. Operation status is in
  // the form of key-value pairs where keys are resource IDs and the values show
  // the status of the operation. In case of failures, the value includes an
  // error code and error message.
  map<string, OperationStatus> operation_status = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
}

message OperationStatus {
  enum ErrorCode {
    ERROR_CODE_UNSPECIFIED = 0;

    INTERNAL_ERROR = 1;

    PERMISSION_DENIED = 2;

    CLUSTER_CONNECTION = 3;
  }

  // Output only. Whether the operation is done or still in progress.
  bool done = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The error code in case of failures.
  ErrorCode error_code = 2;

  // The human-readable error message.
  string error_message = 3;
}

// The label selector, used to group labels on the resources.
message LabelSelector {
  // Resource labels for this selector.
  map<string, string> labels = 1;
}

// The realm selector, used to match realm resources.
message RealmSelector {
  // List of realms to match.
  repeated string realms = 1;
}

// The schedule of a recurring or one time event. The event's time span is
// specified by start_time and end_time. If the scheduled event's timespan is
// larger than the cron_spec + cron_job_duration, the event will be recurring.
// If only cron_spec + cron_job_duration are specified, the event is effective
// starting at the local time specified by cron_spec, and is recurring.
//
//   start_time|-------[cron job]-------[cron job]-------[cron job]---|end_time
//   cron job: cron spec start time + duration
message Schedule {
  // The start time of the event.
  google.protobuf.Timestamp start_time = 1;

  // The end time of the event.
  google.protobuf.Timestamp end_time = 2;

  // The duration for the cron job event. The duration of the event is effective
  // after the cron job's start time.
  google.protobuf.Duration cron_job_duration = 3;

  // The cron definition of the scheduled event. See
  // https://en.wikipedia.org/wiki/Cron. Cron spec specifies the local time as
  // defined by the realm.
  string cron_spec = 4;
}

// Encapsulates Agones fleet spec and Agones autoscaler spec sources.
message SpecSource {
  // The game server config resource. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment_id}/configs/{config_id}`.
  string game_server_config_name = 1;

  // The name of the Agones leet config or Agones scaling config used to derive
  // the Agones fleet or Agones autoscaler spec.
  string name = 2;
}

// Details about the Agones resources.
message TargetDetails {
  // Details of the target Agones fleet.
  message TargetFleetDetails {
    // Target Agones fleet specification.
    message TargetFleet {
      // The name of the Agones fleet.
      string name = 1;

      // Encapsulates the source of the Agones fleet spec.
      // The Agones fleet spec source.
      SpecSource spec_source = 2;
    }

    // Target Agones autoscaler policy reference.
    message TargetFleetAutoscaler {
      // The name of the Agones autoscaler.
      string name = 1;

      // Encapsulates the source of the Agones fleet spec.
      // Details about the Agones autoscaler spec.
      SpecSource spec_source = 2;
    }

    // Reference to target Agones fleet.
    TargetFleet fleet = 1;

    // Reference to target Agones fleet autoscaling policy.
    TargetFleetAutoscaler autoscaler = 2;
  }

  // The game server cluster name. Uses the form:
  //
  // `projects/{project}/locations/{location}/realms/{realm}/gameServerClusters/{cluster}`.
  string game_server_cluster_name = 1;

  // The game server deployment name. Uses the form:
  //
  // `projects/{project}/locations/{location}/gameServerDeployments/{deployment_id}`.
  string game_server_deployment_name = 2;

  // Agones fleet details for game server clusters and game server deployments.
  repeated TargetFleetDetails fleet_details = 3;
}

// Encapsulates the Target state.
message TargetState {
  // Details about Agones fleets.
  repeated TargetDetails details = 1;
}

// Details of the deployed Agones fleet.
message DeployedFleetDetails {
  // Agones fleet specification and details.
  message DeployedFleet {
    // DeployedFleetStatus has details about the Agones fleets such as how many
    // are running, how many allocated, and so on.
    message DeployedFleetStatus {
      // The number of GameServer replicas in the READY state in this fleet.
      int64 ready_replicas = 1;

      // The number of GameServer replicas in the ALLOCATED state in this fleet.
      int64 allocated_replicas = 2;

      // The number of GameServer replicas in the RESERVED state in this fleet.
      // Reserved instances won't be deleted on scale down, but won't cause
      // an autoscaler to scale up.
      int64 reserved_replicas = 3;

      // The total number of current GameServer replicas in this fleet.
      int64 replicas = 4;
    }

    // The name of the Agones fleet.
    string fleet = 1;

    // The fleet spec retrieved from the Agones fleet.
    string fleet_spec = 2;

    // The source spec that is used to create the Agones fleet.
    // The GameServerConfig resource may no longer exist in the system.
    SpecSource spec_source = 3;

    // The current status of the Agones fleet.
    // Includes count of game servers in various states.
    DeployedFleetStatus status = 5;
  }

  // Details about the Agones autoscaler.
  message DeployedFleetAutoscaler {
    // The name of the Agones autoscaler.
    string autoscaler = 1;

    // The source spec that is used to create the autoscaler.
    // The GameServerConfig resource may no longer exist in the system.
    SpecSource spec_source = 4;

    // The autoscaler spec retrieved from Agones.
    string fleet_autoscaler_spec = 3;
  }

  // Information about the Agones fleet.
  DeployedFleet deployed_fleet = 1;

  // Information about the Agones autoscaler for that fleet.
  DeployedFleetAutoscaler deployed_autoscaler = 2;
}
