// 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.v1alpha;

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/v1alpha/conversational_search_service.proto";
import "google/cloud/discoveryengine/v1alpha/session.proto";
import "google/protobuf/empty.proto";

option csharp_namespace = "Google.Cloud.DiscoveryEngine.V1Alpha";
option go_package = "cloud.google.com/go/discoveryengine/apiv1alpha/discoveryenginepb;discoveryenginepb";
option java_multiple_files = true;
option java_outer_classname = "SessionServiceProto";
option java_package = "com.google.cloud.discoveryengine.v1alpha";
option objc_class_prefix = "DISCOVERYENGINE";
option php_namespace = "Google\\Cloud\\DiscoveryEngine\\V1alpha";
option ruby_package = "Google::Cloud::DiscoveryEngine::V1alpha";

// Service for managing Sessions and Session-related resources.
service SessionService {
  option (google.api.default_host) = "discoveryengine.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Creates a Session.
  //
  // If the [Session][google.cloud.discoveryengine.v1alpha.Session] to create
  // already exists, an ALREADY_EXISTS error is returned.
  rpc CreateSession(CreateSessionRequest) returns (Session) {
    option (google.api.http) = {
      post: "/v1alpha/{parent=projects/*/locations/*/dataStores/*}/sessions"
      body: "session"
      additional_bindings {
        post: "/v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions"
        body: "session"
      }
      additional_bindings {
        post: "/v1alpha/{parent=projects/*/locations/*/collections/*/engines/*}/sessions"
        body: "session"
      }
    };
    option (google.api.method_signature) = "parent,session";
  }

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

  // Updates a Session.
  //
  // [Session][google.cloud.discoveryengine.v1alpha.Session] action type cannot
  // be changed. If the [Session][google.cloud.discoveryengine.v1alpha.Session]
  // to update does not exist, a NOT_FOUND error is returned.
  rpc UpdateSession(UpdateSessionRequest) returns (Session) {
    option (google.api.http) = {
      patch: "/v1alpha/{session.name=projects/*/locations/*/dataStores/*/sessions/*}"
      body: "session"
      additional_bindings {
        patch: "/v1alpha/{session.name=projects/*/locations/*/collections/*/dataStores/*/sessions/*}"
        body: "session"
      }
      additional_bindings {
        patch: "/v1alpha/{session.name=projects/*/locations/*/collections/*/engines/*/sessions/*}"
        body: "session"
      }
    };
    option (google.api.method_signature) = "session,update_mask";
  }

  // Gets a Session.
  rpc GetSession(GetSessionRequest) returns (Session) {
    option (google.api.http) = {
      get: "/v1alpha/{name=projects/*/locations/*/dataStores/*/sessions/*}"
      additional_bindings {
        get: "/v1alpha/{name=projects/*/locations/*/collections/*/dataStores/*/sessions/*}"
      }
      additional_bindings {
        get: "/v1alpha/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // Lists all Sessions by their parent
  // [DataStore][google.cloud.discoveryengine.v1alpha.DataStore].
  rpc ListSessions(ListSessionsRequest) returns (ListSessionsResponse) {
    option (google.api.http) = {
      get: "/v1alpha/{parent=projects/*/locations/*/dataStores/*}/sessions"
      additional_bindings {
        get: "/v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions"
      }
      additional_bindings {
        get: "/v1alpha/{parent=projects/*/locations/*/collections/*/engines/*}/sessions"
      }
    };
    option (google.api.method_signature) = "parent";
  }

  // Lists metadata for all files in the current session.
  rpc ListFiles(ListFilesRequest) returns (ListFilesResponse) {
    option (google.api.http) = {
      get: "/v1alpha/{parent=projects/*/locations/*/collections/*/engines/*/sessions/*}/files"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Request message for
// [SessionService.ListFiles][google.cloud.discoveryengine.v1alpha.SessionService.ListFiles]
// method.
message ListFilesRequest {
  // Required. The resource name of the Session.
  // Format:
  // `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}`
  // Name of the session resource to which the file belong.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/Session"
    }
  ];

  // Optional. The filter syntax consists of an expression language for
  // constructing a predicate from one or more fields of the files being
  // filtered. Filter expression is case-sensitive. Currently supported field
  // names are:
  // * upload_time
  // * last_add_time
  // * last_use_time
  // * file_name
  // * mime_type
  //
  // Some examples of filters would be:
  // * "file_name = 'file_1'"
  // * "file_name = 'file_1' AND mime_type = 'text/plain'"
  // * "last_use_time > '2025-06-14T12:00:00Z'"
  //
  // For a full description of the filter format, please
  // see https://google.aip.dev/160.
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum number of files to return. The service may return
  // fewer than this value. If unspecified, at most 100 files will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  // If user specifies a value less than or equal to 0 - the request will be
  // rejected with an INVALID_ARGUMENT error.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token received from a previous `ListFiles` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListFiles`
  // must match the call that provided the page token (except `page_size`, which
  // may differ).
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for
// [SessionService.ListFiles][google.cloud.discoveryengine.v1alpha.SessionService.ListFiles]
// method.
message ListFilesResponse {
  // The [FileMetadata][google.cloud.discoveryengine.v1alpha.FileMetadata]s.
  repeated FileMetadata files = 1;

  // A token to retrieve next page of results.
  // Pass this value in the
  // [ListFilesRequest.page_token][google.cloud.discoveryengine.v1main.ListFilesRequest.page_token]
  // field in the subsequent call to `ListFiles` method to
  // retrieve the next page of results.
  string next_page_token = 3;
}
