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

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/discoveryengine/v1/answer.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.DiscoveryEngine.V1";
option go_package = "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb;discoveryenginepb";
option java_multiple_files = true;
option java_outer_classname = "SessionProto";
option java_package = "com.google.cloud.discoveryengine.v1";
option objc_class_prefix = "DISCOVERYENGINE";
option php_namespace = "Google\\Cloud\\DiscoveryEngine\\V1";
option ruby_package = "Google::Cloud::DiscoveryEngine::V1";

// External session proto definition.
message Session {
  option (google.api.resource) = {
    type: "discoveryengine.googleapis.com/Session"
    pattern: "projects/{project}/locations/{location}/dataStores/{data_store}/sessions/{session}"
    pattern: "projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/sessions/{session}"
    pattern: "projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}"
  };

  // Represents a turn, including a query from the user and a
  // answer from service.
  message Turn {
    // The user query.
    Query query = 1;

    // The resource name of the answer to the user query.
    //
    // Only set if the answer generation (/answer API call) happened in this
    // turn.
    string answer = 2 [(google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/Answer"
    }];

    // Output only. In
    // [ConversationalSearchService.GetSession][google.cloud.discoveryengine.v1.ConversationalSearchService.GetSession]
    // API, if
    // [GetSessionRequest.include_answer_details][google.cloud.discoveryengine.v1.GetSessionRequest.include_answer_details]
    // is set to true, this field will be populated when getting answer query
    // session.
    Answer detailed_answer = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Enumeration of the state of the session.
  enum State {
    // State is unspecified.
    STATE_UNSPECIFIED = 0;

    // The session is currently open.
    IN_PROGRESS = 1;
  }

  // Immutable. Fully qualified name
  // `projects/{project}/locations/global/collections/{collection}/engines/{engine}/sessions/*`
  string name = 1 [(google.api.field_behavior) = IMMUTABLE];

  // Optional. The display name of the session.
  //
  // This field is used to identify the session in the UI.
  // By default, the display name is the first turn query text in the session.
  string display_name = 7 [(google.api.field_behavior) = OPTIONAL];

  // The state of the session.
  State state = 2;

  // A unique identifier for tracking users.
  string user_pseudo_id = 3;

  // Turns.
  repeated Turn turns = 4;

  // Output only. The time the session started.
  google.protobuf.Timestamp start_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

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

  // Optional. Whether the session is pinned, pinned session will be displayed
  // on the top of the session list.
  bool is_pinned = 8 [(google.api.field_behavior) = OPTIONAL];
}

// Defines a user inputed query.
message Query {
  // Query content.
  oneof content {
    // Plain text.
    string text = 2;
  }

  // Unique Id for the query.
  string query_id = 1;
}
