// Copyright 2026 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.sql.v1beta4;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/sql/v1beta4/cloud_sql_resources.proto";
import "google/protobuf/timestamp.proto";

option go_package = "cloud.google.com/go/sql/apiv1beta4/sqlpb;sqlpb";
option java_multiple_files = true;
option java_outer_classname = "CloudSqlWorkloadCapturesProto";
option java_package = "com.google.cloud.sql.v1beta4";

// Cloud SQL Workload Captures service.
service SqlWorkloadCapturesService {
  option (google.api.default_host) = "sqladmin.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform,"
      "https://www.googleapis.com/auth/sqlservice.admin";

  // Starts capturing the SQL queries, transactions, and other operations
  // executed on the primary instance. This traffic is securely stored and forms
  // a "captured workload". This workload can be replayed later on a different
  // instance to safely test performance impacts, database upgrades,
  // configuration changes etc. before applying them to production.
  rpc Start(SqlWorkloadCapturesStartRequest) returns (Operation) {
    option (google.api.http) = {
      post: "/sql/v1beta4/projects/{project}/instances/{instance}/workloadCaptures:start"
      body: "*"
    };
  }

  // Stops capturing the query traffic and related operations executed on the
  // primary instance.
  rpc Stop(SqlWorkloadCapturesStopRequest) returns (Operation) {
    option (google.api.http) = {
      post: "/sql/v1beta4/projects/{project}/instances/{instance}/workloadCaptures:stop"
      body: "*"
    };
  }

  // Starts executing a captured workload on a separate Cloud SQL instance
  // provisioned for workload replay. This target instance simulates the
  // production environment without affecting the primary instance.
  rpc StartReplay(SqlWorkloadCapturesStartReplayRequest) returns (Operation) {
    option (google.api.http) = {
      post: "/sql/v1beta4/projects/{project}/instances/{instance}/workloadCaptures/{workload_id}:startReplay"
      body: "*"
    };
  }

  // Stops an active workload replay on the target Cloud SQL replay instance.
  rpc StopReplay(SqlWorkloadCapturesStopReplayRequest) returns (Operation) {
    option (google.api.http) = {
      post: "/sql/v1beta4/projects/{project}/instances/{instance}/workloadCaptures:stopReplay"
      body: "*"
    };
  }

  // Lists all captured workloads associated with the instance.
  rpc List(SqlWorkloadCapturesListRequest)
      returns (WorkloadCapturesListResponse) {
    option (google.api.http) = {
      get: "/sql/v1beta4/projects/{project}/instances/{instance}/workloadCaptures"
    };
  }
}

// Request to start recording traffic from the primary instance (captured
// workload).
message SqlWorkloadCapturesStartRequest {
  // Required. Project ID of the project that contains the instance.
  string project = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Cloud SQL instance ID. This does not include the project ID.
  string instance = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Contains details about the start workload capture operation.
  StartWorkloadCaptureContext start_workload_capture_context = 100
      [(google.api.field_behavior) = OPTIONAL];
}

// Request to stop recording traffic from the primary instance.
message SqlWorkloadCapturesStopRequest {
  // Required. Project ID of the project that contains the instance.
  string project = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Cloud SQL instance ID. This does not include the project ID.
  string instance = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Contains details about the stop workload capture operation.
  StopWorkloadCaptureContext stop_workload_capture_context = 100
      [(google.api.field_behavior) = OPTIONAL];
}

// Request to start executing a captured workload on a replay instance (the
// Cloud SQL instance where the recorded SQL queries are executed).
message SqlWorkloadCapturesStartReplayRequest {
  // Required. Project ID of the project that contains the instance.
  string project = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Cloud SQL instance ID. This does not include the project ID.
  string instance = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. Contains details about the start workload replay operation.
  StartWorkloadReplayContext start_workload_replay_context = 100
      [(google.api.field_behavior) = REQUIRED];

  // Required. The ID of the workload to replay.
  string workload_id = 4 [(google.api.field_behavior) = REQUIRED];
}

// Request to stop an active workload replay on a target Cloud SQL replay
// instance.
message SqlWorkloadCapturesStopReplayRequest {
  // Required. Project ID of the project that contains the target replay
  // instance.
  string project = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Cloud SQL instance ID of the target replay instance. This does
  // not include the project ID.
  string instance = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Contains details about the stop workload replay operation.
  StopWorkloadReplayContext stop_workload_replay_context = 100
      [(google.api.field_behavior) = OPTIONAL];
}

// Instance list captured workloads request.
message SqlWorkloadCapturesListRequest {
  // Required. Project ID of the project that contains the instance.
  string project = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Cloud SQL instance ID. This does not include the project ID.
  string instance = 2 [(google.api.field_behavior) = REQUIRED];
}

// Instance list captured workloads response.
message WorkloadCapturesListResponse {
  // List of captured workloads for the instance.
  repeated WorkloadCapture workload_captures = 1;

  // This is always `sql#workloadCapturesList`.
  string kind = 2;
}

// Captured workload for an instance.
message WorkloadCapture {
  // State of the workload capture.
  enum State {
    // Default value. This value is unused.
    STATE_UNSPECIFIED = 0;

    // Workload capture is currently running.
    RUNNING = 1;

    // Workload capture completed successfully. This state is set when the user
    // explicitly stops the capture.
    COMPLETED = 2;

    // Workload capture failed.
    FAILED = 3;

    // Workload capture was terminated automatically. This state is set when
    // Cloud SQL automatically stops the capture due to a conflicting operation
    // or when the maximum duration is reached.
    TERMINATED = 4;
  }

  // Output only. The ID of the captured workload.
  string workload_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The name of the source instance.
  string source_instance = 2 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "sqladmin.googleapis.com/Instance"
    }
  ];

  // Output only. The state of the workload capture.
  State workload_capture_state = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The start time of the workload capture.
  google.protobuf.Timestamp start_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The end time of the workload capture.
  google.protobuf.Timestamp end_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The name of the replay instance, if live replay was enabled.
  optional string replay_instance = 6 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "sqladmin.googleapis.com/Instance"
    }
  ];

  // Output only. The retention period in days for the captured workload.
  optional int32 retention_days = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The base backup ID associated with the workload capture.
  optional string backup_id = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}
