// Copyright 2025 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.support.v2;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/support/v2/case.proto";
import "google/cloud/support/v2/escalation.proto";
import "google/protobuf/field_mask.proto";

option csharp_namespace = "Google.Cloud.Support.V2";
option go_package = "cloud.google.com/go/support/apiv2/supportpb;supportpb";
option java_multiple_files = true;
option java_outer_classname = "CaseServiceProto";
option java_package = "com.google.cloud.support.v2";
option php_namespace = "Google\\Cloud\\Support\\V2";
option ruby_package = "Google::Cloud::Support::V2";

// A service to manage Google Cloud support cases.
service CaseService {
  option (google.api.default_host) = "cloudsupport.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Retrieve a case.
  rpc GetCase(GetCaseRequest) returns (Case) {
    option (google.api.http) = {
      get: "/v2/{name=projects/*/cases/*}"
      additional_bindings { get: "/v2/{name=organizations/*/cases/*}" }
    };
    option (google.api.method_signature) = "name";
  }

  // Retrieve all cases under a parent, but not its children.
  //
  // For example, listing cases under an organization only returns the cases
  // that are directly parented by that organization. To retrieve cases
  // under an organization and its projects, use `cases.search`.
  rpc ListCases(ListCasesRequest) returns (ListCasesResponse) {
    option (google.api.http) = {
      get: "/v2/{parent=projects/*}/cases"
      additional_bindings { get: "/v2/{parent=organizations/*}/cases" }
    };
    option (google.api.method_signature) = "parent";
  }

  // Search for cases using a query.
  rpc SearchCases(SearchCasesRequest) returns (SearchCasesResponse) {
    option (google.api.http) = {
      get: "/v2/{parent=projects/*}/cases:search"
      additional_bindings { get: "/v2/{parent=organizations/*}/cases:search" }
    };
  }

  // Create a new case and associate it with a parent.
  //
  // It must have the following fields set: `display_name`, `description`,
  // `classification`, and `priority`. If you're just testing the API and don't
  // want to route your case to an agent, set `testCase=true`.
  rpc CreateCase(CreateCaseRequest) returns (Case) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/cases"
      body: "case"
      additional_bindings {
        post: "/v2/{parent=organizations/*}/cases"
        body: "case"
      }
    };
    option (google.api.method_signature) = "parent,case";
  }

  // Update a case. Only some fields can be updated.
  rpc UpdateCase(UpdateCaseRequest) returns (Case) {
    option (google.api.http) = {
      patch: "/v2/{case.name=projects/*/cases/*}"
      body: "case"
      additional_bindings {
        patch: "/v2/{case.name=organizations/*/cases/*}"
        body: "case"
      }
    };
    option (google.api.method_signature) = "case,update_mask";
  }

  // Escalate a case, starting the Google Cloud Support escalation management
  // process.
  //
  // This operation is only available for some support services. Go to
  // https://cloud.google.com/support and look for 'Technical support
  // escalations' in the feature list to find out which ones let you
  // do that.
  rpc EscalateCase(EscalateCaseRequest) returns (Case) {
    option (google.api.http) = {
      post: "/v2/{name=projects/*/cases/*}:escalate"
      body: "*"
      additional_bindings {
        post: "/v2/{name=organizations/*/cases/*}:escalate"
        body: "*"
      }
    };
  }

  // Close a case.
  rpc CloseCase(CloseCaseRequest) returns (Case) {
    option (google.api.http) = {
      post: "/v2/{name=projects/*/cases/*}:close"
      body: "*"
      additional_bindings {
        post: "/v2/{name=organizations/*/cases/*}:close"
        body: "*"
      }
    };
  }

  // Retrieve valid classifications to use when creating a support case.
  //
  // Classifications are hierarchical. Each classification is a string
  // containing all levels of the hierarchy separated by `" > "`. For example,
  // `"Technical Issue > Compute > Compute Engine"`.
  //
  // Classification IDs returned by this endpoint are valid for at least six
  // months. When a classification is deactivated, this endpoint immediately
  // stops returning it. After six months, `case.create` requests using the
  // classification will fail.
  rpc SearchCaseClassifications(SearchCaseClassificationsRequest)
      returns (SearchCaseClassificationsResponse) {
    option (google.api.http) = {
      get: "/v2/caseClassifications:search"
    };
  }
}

// The request message for the GetCase endpoint.
message GetCaseRequest {
  // Required. The full name of a case to be retrieved.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudsupport.googleapis.com/Case"
    }
  ];
}

// The request message for the CreateCase endpoint.
message CreateCaseRequest {
  // Required. The name of the parent under which the case should be created.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "cloudsupport.googleapis.com/Case"
    }
  ];

  // Required. The case to be created.
  Case case = 2 [(google.api.field_behavior) = REQUIRED];
}

// The request message for the ListCases endpoint.
message ListCasesRequest {
  // Required. The name of a parent to list cases under.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "cloudsupport.googleapis.com/Case"
    }
  ];

  // An expression used to filter cases.
  //
  // If it's an empty string, then no filtering happens. Otherwise, the endpoint
  // returns the cases that match the filter.
  //
  // Expressions use the following fields separated by `AND` and specified with
  // `=`:
  //
  // - `state`: Can be `OPEN` or `CLOSED`.
  // - `priority`: Can be `P0`, `P1`, `P2`, `P3`, or `P4`. You
  // can specify multiple values for priority using the `OR` operator. For
  // example, `priority=P1 OR priority=P2`.
  // - `creator.email`: The email address of the case creator.
  //
  // EXAMPLES:
  //
  // - `state=CLOSED`
  // - `state=OPEN AND creator.email="tester@example.com"`
  // - `state=OPEN AND (priority=P0 OR priority=P1)`
  string filter = 2;

  // The maximum number of cases fetched with each request. Defaults to 10.
  int32 page_size = 4;

  // A token identifying the page of results to return. If unspecified, the
  // first page is retrieved.
  string page_token = 5;
}

// The response message for the ListCases endpoint.
message ListCasesResponse {
  // The list of cases associated with the parent after any
  // filters have been applied.
  repeated Case cases = 1;

  // A token to retrieve the next page of results. Set this in the `page_token`
  // field of subsequent `cases.list` requests. If unspecified, there are no
  // more results to retrieve.
  string next_page_token = 2;
}

// The request message for the SearchCases endpoint.
message SearchCasesRequest {
  // The name of the parent resource to search for cases under.
  string parent = 4;

  // An expression used to filter cases.
  //
  // Expressions use the following fields separated by `AND` and specified with
  // `=`:
  //
  // - `organization`: An organization name in the form
  // `organizations/<organization_id>`.
  // - `project`: A project name in the form `projects/<project_id>`.
  // - `state`: Can be `OPEN` or `CLOSED`.
  // - `priority`: Can be `P0`, `P1`, `P2`, `P3`, or `P4`. You
  // can specify multiple values for priority using the `OR` operator. For
  // example, `priority=P1 OR priority=P2`.
  // - `creator.email`: The email address of the case creator.
  //
  // You must specify either `organization` or `project`.
  //
  // To search across `displayName`, `description`, and comments, use a global
  // restriction with no keyword or operator. For example, `"my search"`.
  //
  // To search only cases updated after a certain date, use `update_time`
  // restricted with that particular date, time, and timezone in ISO datetime
  // format. For example, `update_time>"2020-01-01T00:00:00-05:00"`.
  // `update_time` only supports the greater than operator (`>`).
  //
  // Examples:
  //
  // - `organization="organizations/123456789"`
  // - `project="projects/my-project-id"`
  // - `project="projects/123456789"`
  // - `organization="organizations/123456789" AND state=CLOSED`
  // - `project="projects/my-project-id" AND creator.email="tester@example.com"`
  // - `project="projects/my-project-id" AND (priority=P0 OR priority=P1)`
  string query = 1;

  // The maximum number of cases fetched with each request. The default page
  // size is 10.
  int32 page_size = 2;

  // A token identifying the page of results to return. If unspecified, the
  // first page is retrieved.
  string page_token = 3;
}

// The response message for the SearchCases endpoint.
message SearchCasesResponse {
  // The list of cases associated with the parent after any
  // filters have been applied.
  repeated Case cases = 1;

  // A token to retrieve the next page of results. Set this in the
  // `page_token` field of subsequent `cases.search` requests. If unspecified,
  // there are no more results to retrieve.
  string next_page_token = 2;
}

// The request message for the EscalateCase endpoint.
message EscalateCaseRequest {
  // Required. The name of the case to be escalated.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudsupport.googleapis.com/Case"
    }
  ];

  // The escalation information to be sent with the escalation request.
  Escalation escalation = 2;
}

// The request message for the UpdateCase endpoint
message UpdateCaseRequest {
  // Required. The case to update.
  Case case = 1 [(google.api.field_behavior) = REQUIRED];

  // A list of attributes of the case that should be updated. Supported values
  // are `priority`, `display_name`, and `subscriber_email_addresses`. If no
  // fields are specified, all supported fields are updated.
  //
  // Be careful - if you do not provide a field mask, then you might
  // accidentally clear some fields. For example, if you leave the field mask
  // empty and do not provide a value for `subscriber_email_addresses`, then
  // `subscriber_email_addresses` is updated to empty.
  google.protobuf.FieldMask update_mask = 2;
}

// The request message for the CloseCase endpoint.
message CloseCaseRequest {
  // Required. The name of the case to close.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudsupport.googleapis.com/Case"
    }
  ];
}

// The request message for the SearchCaseClassifications endpoint.
message SearchCaseClassificationsRequest {
  // An expression used to filter case classifications.
  //
  // If it's an empty string, then no filtering happens. Otherwise, case
  // classifications will be returned that match the filter.
  string query = 1;

  // The maximum number of classifications fetched with each request.
  int32 page_size = 2;

  // A token identifying the page of results to return. If unspecified, the
  // first page is retrieved.
  string page_token = 3;
}

// The response message for SearchCaseClassifications endpoint.
message SearchCaseClassificationsResponse {
  // The classifications retrieved.
  repeated CaseClassification case_classifications = 1;

  // A token to retrieve the next page of results. Set this in the `page_token`
  // field of subsequent `caseClassifications.list` requests. If unspecified,
  // there are no more results to retrieve.
  string next_page_token = 2;
}
