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

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";

option go_package = "cloud.google.com/go/ces/apiv1/cespb;cespb";
option java_multiple_files = true;
option java_outer_classname = "WidgetServiceProto";
option java_package = "com.google.cloud.ces.v1";

// Provides APIs for widgets to interact with CES APIs.
service WidgetService {
  option (google.api.default_host) = "ces.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/ces,"
      "https://www.googleapis.com/auth/cloud-platform";

  // Generates a session scoped token for chat widget to authenticate with
  // Session APIs.
  rpc GenerateChatToken(GenerateChatTokenRequest)
      returns (GenerateChatTokenResponse) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/apps/*/sessions/*}:generateChatToken"
      body: "*"
    };
  }
}

// Request message for
// [WidgetService.GenerateChatToken][google.cloud.ces.v1.WidgetService.GenerateChatToken].
message GenerateChatTokenRequest {
  // Required. The session name to generate the chat token for.
  // Format:
  // projects/{project}/locations/{location}/apps/{app}/sessions/{session}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "ces.googleapis.com/Session" }
  ];

  // Required. The deployment of the app to use for the session.
  // Format:
  // projects/{project}/locations/{location}/apps/{app}/deployments/{deployment}
  string deployment = 2 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "ces.googleapis.com/Deployment" }
  ];

  // Optional. The reCAPTCHA token generated by the client-side chat widget.
  string recaptcha_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Indicates if live handoff is enabled for the session.
  bool live_handoff_enabled = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for
// [WidgetService.GenerateChatToken][google.cloud.ces.v1.WidgetService.GenerateChatToken].
message GenerateChatTokenResponse {
  // The session scoped token for chat widget to authenticate with Session APIs.
  string chat_token = 1;

  // The time at which the chat token expires.
  google.protobuf.Timestamp expire_time = 2;
}
