// Copyright 2022 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.discoveryengine.v1beta;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/discoveryengine/v1beta/conversation.proto";
import "google/cloud/discoveryengine/v1beta/search_service.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";

option csharp_namespace = "Google.Cloud.DiscoveryEngine.V1Beta";
option go_package = "cloud.google.com/go/discoveryengine/apiv1beta/discoveryenginepb;discoveryenginepb";
option java_multiple_files = true;
option java_outer_classname = "ConversationalSearchServiceProto";
option java_package = "com.google.cloud.discoveryengine.v1beta";
option objc_class_prefix = "DISCOVERYENGINE";
option php_namespace = "Google\\Cloud\\DiscoveryEngine\\V1beta";
option ruby_package = "Google::Cloud::DiscoveryEngine::V1beta";

// Service for conversational search.
service ConversationalSearchService {
  option (google.api.default_host) = "discoveryengine.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Converses a conversation.
  rpc ConverseConversation(ConverseConversationRequest)
      returns (ConverseConversationResponse) {
    option (google.api.http) = {
      post: "/v1beta/{name=projects/*/locations/*/dataStores/*/conversations/*}:converse"
      body: "*"
      additional_bindings {
        post: "/v1beta/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}:converse"
        body: "*"
      }
    };
    option (google.api.method_signature) = "name,query";
  }

  // Creates a Conversation.
  //
  // If the [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to
  // create already exists, an ALREADY_EXISTS error is returned.
  rpc CreateConversation(CreateConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      post: "/v1beta/{parent=projects/*/locations/*/dataStores/*}/conversations"
      body: "conversation"
      additional_bindings {
        post: "/v1beta/{parent=projects/*/locations/*/collections/*/dataStores/*}/conversations"
        body: "conversation"
      }
    };
    option (google.api.method_signature) = "parent,conversation";
  }

  // Deletes a Conversation.
  //
  // If the [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to
  // delete does not exist, a NOT_FOUND error is returned.
  rpc DeleteConversation(DeleteConversationRequest)
      returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1beta/{name=projects/*/locations/*/dataStores/*/conversations/*}"
      additional_bindings {
        delete: "/v1beta/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // Updates a Conversation.
  //
  // [Conversation][google.cloud.discoveryengine.v1beta.Conversation] action
  // type cannot be changed. If the
  // [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to update
  // does not exist, a NOT_FOUND error is returned.
  rpc UpdateConversation(UpdateConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      patch: "/v1beta/{conversation.name=projects/*/locations/*/dataStores/*/conversations/*}"
      body: "conversation"
      additional_bindings {
        patch: "/v1beta/{conversation.name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}"
        body: "conversation"
      }
    };
    option (google.api.method_signature) = "conversation,update_mask";
  }

  // Gets a Conversation.
  rpc GetConversation(GetConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      get: "/v1beta/{name=projects/*/locations/*/dataStores/*/conversations/*}"
      additional_bindings {
        get: "/v1beta/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // Lists all Conversations by their parent
  // [DataStore][google.cloud.discoveryengine.v1beta.DataStore].
  rpc ListConversations(ListConversationsRequest)
      returns (ListConversationsResponse) {
    option (google.api.http) = {
      get: "/v1beta/{parent=projects/*/locations/*/dataStores/*}/conversations"
      additional_bindings {
        get: "/v1beta/{parent=projects/*/locations/*/collections/*/dataStores/*}/conversations"
      }
    };
    option (google.api.method_signature) = "parent";
  }
}

// Request message for
// [ConversationalSearchService.ConverseConversation][google.cloud.discoveryengine.v1beta.ConversationalSearchService.ConverseConversation]
// method.
message ConverseConversationRequest {
  // Required. The resource name of the Conversation to get. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/{conversation_id}`.
  // Use
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/-`
  // to activate auto session mode, which automatically creates a new
  // conversation inside a ConverseConversation session.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/Conversation"
    }
  ];

  // Required. Current user input.
  TextInput query = 2 [(google.api.field_behavior) = REQUIRED];

  // The resource name of the Serving Config to use. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/servingConfigs/{serving_config_id}`
  // If this is not set, the default serving config will be used.
  string serving_config = 3 [(google.api.resource_reference) = {
    type: "discoveryengine.googleapis.com/ServingConfig"
  }];

  // The conversation to be used by auto session only. The name field will be
  // ignored as we automatically assign new name for the conversation in auto
  // session.
  Conversation conversation = 5;

  // Whether to turn on safe search.
  bool safe_search = 6;

  // The user labels applied to a resource must meet the following requirements:
  //
  // * Each resource can have multiple labels, up to a maximum of 64.
  // * Each label must be a key-value pair.
  // * Keys have a minimum length of 1 character and a maximum length of 63
  //   characters and cannot be empty. Values can be empty and have a maximum
  //   length of 63 characters.
  // * Keys and values can contain only lowercase letters, numeric characters,
  //   underscores, and dashes. All characters must use UTF-8 encoding, and
  //   international characters are allowed.
  // * The key portion of a label must be unique. However, you can use the same
  //   key with multiple resources.
  // * Keys must start with a lowercase letter or international character.
  //
  // See [Google Cloud
  // Document](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
  // for more details.
  map<string, string> user_labels = 7;

  // A specification for configuring the summary returned in the response.
  SearchRequest.ContentSearchSpec.SummarySpec summary_spec = 8;
}

// Response message for
// [ConversationalSearchService.ConverseConversation][google.cloud.discoveryengine.v1beta.ConversationalSearchService.ConverseConversation]
// method.
message ConverseConversationResponse {
  // Answer to the current query.
  Reply reply = 1;

  // Updated conversation including the answer.
  Conversation conversation = 2;

  // Suggested related questions.
  repeated string related_questions = 6;

  // Search Results.
  repeated SearchResponse.SearchResult search_results = 3;
}

// Request for CreateConversation method.
message CreateConversationRequest {
  // Required. Full resource name of parent data store. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/DataStore"
    }
  ];

  // Required. The conversation to create.
  Conversation conversation = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request for UpdateConversation method.
message UpdateConversationRequest {
  // Required. The Conversation to update.
  Conversation conversation = 1 [(google.api.field_behavior) = REQUIRED];

  // Indicates which fields in the provided
  // [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to update.
  // The following are NOT supported:
  //
  // * [conversation.name][]
  //
  // If not set or empty, all supported fields are updated.
  google.protobuf.FieldMask update_mask = 2;
}

// Request for DeleteConversation method.
message DeleteConversationRequest {
  // Required. The resource name of the Conversation to delete. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/{conversation_id}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/Conversation"
    }
  ];
}

// Request for GetConversation method.
message GetConversationRequest {
  // Required. The resource name of the Conversation to get. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/{conversation_id}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/Conversation"
    }
  ];
}

// Request for ListConversations method.
message ListConversationsRequest {
  // Required. The data store resource name. Format:
  // `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/DataStore"
    }
  ];

  // Maximum number of results to return. If unspecified, defaults
  // to 50. Max allowed value is 1000.
  int32 page_size = 2;

  // A page token, received from a previous `ListConversations` call.
  // Provide this to retrieve the subsequent page.
  string page_token = 3;

  // A filter to apply on the list results. The supported features are:
  // user_pseudo_id, state.
  //
  // Example:
  // "user_pseudo_id = some_id"
  string filter = 4;

  // A comma-separated list of fields to order by, sorted in ascending order.
  // Use "desc" after a field name for descending.
  // Supported fields:
  //   * `update_time`
  //   * `create_time`
  //   * `conversation_name`
  //
  // Example:
  // "update_time desc"
  // "create_time"
  string order_by = 5;
}

// Response for ListConversations method.
message ListConversationsResponse {
  // All the Conversations for a given data store.
  repeated Conversation conversations = 1;

  // Pagination token, if not returned indicates the last page.
  string next_page_token = 2;
}
