// Copyright 2021 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.dialogflow.cx.v3beta1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/dialogflow/cx/v3beta1/advanced_settings.proto";
import "google/cloud/dialogflow/cx/v3beta1/flow.proto";
import "google/cloud/dialogflow/cx/v3beta1/security_settings.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";

option cc_enable_arenas = true;
option csharp_namespace = "Google.Cloud.Dialogflow.Cx.V3Beta1";
option go_package = "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3beta1;cx";
option java_multiple_files = true;
option java_outer_classname = "AgentProto";
option java_package = "com.google.cloud.dialogflow.cx.v3beta1";
option objc_class_prefix = "DF";

// Service for managing [Agents][google.cloud.dialogflow.cx.v3beta1.Agent].
service Agents {
  option (google.api.default_host) = "dialogflow.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform,"
      "https://www.googleapis.com/auth/dialogflow";

  // Returns the list of all agents in the specified location.
  rpc ListAgents(ListAgentsRequest) returns (ListAgentsResponse) {
    option (google.api.http) = {
      get: "/v3beta1/{parent=projects/*/locations/*}/agents"
    };
    option (google.api.method_signature) = "parent";
  }

  // Retrieves the specified agent.
  rpc GetAgent(GetAgentRequest) returns (Agent) {
    option (google.api.http) = {
      get: "/v3beta1/{name=projects/*/locations/*/agents/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates an agent in the specified location.
  //
  // Note: You should always train a flow prior to sending it queries. See the
  // [training
  // documentation](https://cloud.google.com/dialogflow/cx/docs/concept/training).
  rpc CreateAgent(CreateAgentRequest) returns (Agent) {
    option (google.api.http) = {
      post: "/v3beta1/{parent=projects/*/locations/*}/agents"
      body: "agent"
    };
    option (google.api.method_signature) = "parent,agent";
  }

  // Updates the specified agent.
  //
  // Note: You should always train a flow prior to sending it queries. See the
  // [training
  // documentation](https://cloud.google.com/dialogflow/cx/docs/concept/training).
  rpc UpdateAgent(UpdateAgentRequest) returns (Agent) {
    option (google.api.http) = {
      patch: "/v3beta1/{agent.name=projects/*/locations/*/agents/*}"
      body: "agent"
    };
    option (google.api.method_signature) = "agent,update_mask";
  }

  // Deletes the specified agent.
  rpc DeleteAgent(DeleteAgentRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v3beta1/{name=projects/*/locations/*/agents/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Exports the specified agent to a binary file.
  rpc ExportAgent(ExportAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v3beta1/{name=projects/*/locations/*/agents/*}:export"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "ExportAgentResponse"
      metadata_type: "google.protobuf.Struct"
    };
  }

  // Restores the specified agent from a binary file.
  //
  // Replaces the current agent with a new one. Note that all existing resources
  // in agent (e.g. intents, entity types, flows) will be removed.
  //
  // Note: You should always train a flow prior to sending it queries. See the
  // [training
  // documentation](https://cloud.google.com/dialogflow/cx/docs/concept/training).
  rpc RestoreAgent(RestoreAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v3beta1/{name=projects/*/locations/*/agents/*}:restore"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "google.protobuf.Struct"
    };
  }

  // Validates the specified agent and creates or updates validation results.
  // The agent in draft version is validated. Please call this API after the
  // training is completed to get the complete validation results.
  rpc ValidateAgent(ValidateAgentRequest) returns (AgentValidationResult) {
    option (google.api.http) = {
      post: "/v3beta1/{name=projects/*/locations/*/agents/*}:validate"
      body: "*"
    };
  }

  // Gets the latest agent validation result. Agent validation is performed
  // when ValidateAgent is called.
  rpc GetAgentValidationResult(GetAgentValidationResultRequest) returns (AgentValidationResult) {
    option (google.api.http) = {
      get: "/v3beta1/{name=projects/*/locations/*/agents/*/validationResult}"
    };
    option (google.api.method_signature) = "name";
  }
}

// Settings related to speech recognition.
message SpeechToTextSettings {
  // Whether to use speech adaptation for speech recognition.
  bool enable_speech_adaptation = 1;
}

// Agents are best described as Natural Language Understanding (NLU) modules
// that transform user requests into actionable data. You can include agents
// in your app, product, or service to determine user intent and respond to the
// user in a natural way.
//
// After you create an agent, you can add [Intents][google.cloud.dialogflow.cx.v3beta1.Intent],
// [Entity Types][google.cloud.dialogflow.cx.v3beta1.EntityType], [Flows][google.cloud.dialogflow.cx.v3beta1.Flow], [Fulfillments][google.cloud.dialogflow.cx.v3beta1.Fulfillment],
// [Webhooks][google.cloud.dialogflow.cx.v3beta1.Webhook], and so on to manage the conversation flows..
message Agent {
  option (google.api.resource) = {
    type: "dialogflow.googleapis.com/Agent"
    pattern: "projects/{project}/locations/{location}/agents/{agent}"
  };

  // The unique identifier of the agent.
  // Required for the [Agents.UpdateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.UpdateAgent] method. [Agents.CreateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.CreateAgent]
  // populates the name automatically.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1;

  // Required. The human-readable name of the agent, unique within the location.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. Immutable. The default language of the agent as a language tag.
  // See [Language
  // Support](https://cloud.google.com/dialogflow/cx/docs/reference/language)
  // for a list of the currently supported language codes.
  // This field cannot be set by the [Agents.UpdateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.UpdateAgent] method.
  string default_language_code = 3 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.field_behavior) = IMMUTABLE
  ];

  // The list of all languages supported by the agent (except for the
  // `default_language_code`).
  repeated string supported_language_codes = 4;

  // Required. The time zone of the agent from the [time zone
  // database](https://www.iana.org/time-zones), e.g., America/New_York,
  // Europe/Paris.
  string time_zone = 5 [(google.api.field_behavior) = REQUIRED];

  // The description of the agent. The maximum length is 500 characters. If
  // exceeded, the request is rejected.
  string description = 6;

  // The URI of the agent's avatar. Avatars are used throughout the Dialogflow
  // console and in the self-hosted [Web
  // Demo](https://cloud.google.com/dialogflow/docs/integrations/web-demo)
  // integration.
  string avatar_uri = 7;

  // Speech recognition related settings.
  SpeechToTextSettings speech_to_text_settings = 13;

  // Immutable. Name of the start flow in this agent. A start flow will be automatically
  // created when the agent is created, and can only be deleted by deleting the
  // agent.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent
  // ID>/flows/<Flow ID>`.
  string start_flow = 16 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Flow"
    }
  ];

  // Name of the [SecuritySettings][google.cloud.dialogflow.cx.v3beta1.SecuritySettings] reference for the agent.
  // Format: `projects/<Project ID>/locations/<Location
  // ID>/securitySettings/<Security Settings ID>`.
  string security_settings = 17 [(google.api.resource_reference) = {
                                   type: "dialogflow.googleapis.com/SecuritySettings"
                                 }];

  // Indicates if stackdriver logging is enabled for the agent.
  // Please use [agent.advanced_settings][google.cloud.dialogflow.cx.v3beta1.AdvancedSettings.LoggingSettings]
  // instead.
  bool enable_stackdriver_logging = 18 [deprecated = true];

  // Indicates if automatic spell correction is enabled in detect intent
  // requests.
  bool enable_spell_correction = 20;

  // Hierarchical advanced settings for this agent. The settings exposed at the
  // lower level overrides the settings exposed at the higher level.
  AdvancedSettings advanced_settings = 22;
}

// The request message for [Agents.ListAgents][google.cloud.dialogflow.cx.v3beta1.Agents.ListAgents].
message ListAgentsRequest {
  // Required. The location to list all agents for.
  // Format: `projects/<Project ID>/locations/<Location ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "dialogflow.googleapis.com/Agent"
    }
  ];

  // The maximum number of items to return in a single page. By default 100 and
  // at most 1000.
  int32 page_size = 2;

  // The next_page_token value returned from a previous list request.
  string page_token = 3;
}

// The response message for [Agents.ListAgents][google.cloud.dialogflow.cx.v3beta1.Agents.ListAgents].
message ListAgentsResponse {
  // The list of agents. There will be a maximum number of items returned based
  // on the page_size field in the request.
  repeated Agent agents = 1;

  // Token to retrieve the next page of results, or empty if there are no more
  // results in the list.
  string next_page_token = 2;
}

// The request message for [Agents.GetAgent][google.cloud.dialogflow.cx.v3beta1.Agents.GetAgent].
message GetAgentRequest {
  // Required. The name of the agent.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];
}

// The request message for [Agents.CreateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.CreateAgent].
message CreateAgentRequest {
  // Required. The location to create a agent for.
  // Format: `projects/<Project ID>/locations/<Location ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "dialogflow.googleapis.com/Agent"
    }
  ];

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

// The request message for [Agents.UpdateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.UpdateAgent].
message UpdateAgentRequest {
  // Required. The agent to update.
  Agent agent = 1 [(google.api.field_behavior) = REQUIRED];

  // The mask to control which fields get updated. If the mask is not present,
  // all fields will be updated.
  google.protobuf.FieldMask update_mask = 2;
}

// The request message for [Agents.DeleteAgent][google.cloud.dialogflow.cx.v3beta1.Agents.DeleteAgent].
message DeleteAgentRequest {
  // Required. The name of the agent to delete.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];
}

// The request message for [Agents.ExportAgent][google.cloud.dialogflow.cx.v3beta1.Agents.ExportAgent].
message ExportAgentRequest {
  // Required. The name of the agent to export.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];

  // Optional. The [Google Cloud Storage](https://cloud.google.com/storage/docs/) URI to
  // export the agent to. The format of this URI must be
  // `gs://<bucket-name>/<object-name>`.
  // If left unspecified, the serialized agent is returned inline.
  string agent_uri = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Environment name. If not set, draft environment is assumed.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent
  // ID>/environments/<Environment ID>`.
  string environment = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Environment"
    }
  ];
}

// The response message for [Agents.ExportAgent][google.cloud.dialogflow.cx.v3beta1.Agents.ExportAgent].
message ExportAgentResponse {
  // The exported agent.
  oneof agent {
    // The URI to a file containing the exported agent. This field is populated
    // only if `agent_uri` is specified in [ExportAgentRequest][google.cloud.dialogflow.cx.v3beta1.ExportAgentRequest].
    string agent_uri = 1;

    // Uncompressed raw byte content for agent.
    bytes agent_content = 2;
  }
}

// The request message for [Agents.RestoreAgent][google.cloud.dialogflow.cx.v3beta1.Agents.RestoreAgent].
message RestoreAgentRequest {
  // Restore option.
  enum RestoreOption {
    // Unspecified. Treated as KEEP.
    RESTORE_OPTION_UNSPECIFIED = 0;

    // Always respect the settings from the exported agent file. It may cause
    // a restoration failure if some settings (e.g. model type) are not
    // supported in the target agent.
    KEEP = 1;

    // Fallback to default settings if some settings are not supported in the
    // target agent.
    FALLBACK = 2;
  }

  // Required. The name of the agent to restore into.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];

  // Required. The agent to restore.
  oneof agent {
    // The [Google Cloud Storage](https://cloud.google.com/storage/docs/) URI
    // to restore agent from. The format of this URI must be
    // `gs://<bucket-name>/<object-name>`.
    string agent_uri = 2;

    // Uncompressed raw byte content for agent.
    bytes agent_content = 3;
  }

  // Agent restore mode. If not specified, `KEEP` is assumed.
  RestoreOption restore_option = 5;
}

// The request message for [Agents.ValidateAgent][google.cloud.dialogflow.cx.v3beta1.Agents.ValidateAgent].
message ValidateAgentRequest {
  // Required. The agent to validate.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];

  // If not specified, the agent's default language is used.
  string language_code = 2;
}

// The request message for [Agents.GetAgentValidationResult][google.cloud.dialogflow.cx.v3beta1.Agents.GetAgentValidationResult].
message GetAgentValidationResultRequest {
  // Required. The agent name.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent
  // ID>/validationResult`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/AgentValidationResult"
    }
  ];

  // If not specified, the agent's default language is used.
  string language_code = 2;
}

// The response message for [Agents.GetAgentValidationResult][google.cloud.dialogflow.cx.v3beta1.Agents.GetAgentValidationResult].
message AgentValidationResult {
  option (google.api.resource) = {
    type: "dialogflow.googleapis.com/AgentValidationResult"
    pattern: "projects/{project}/locations/{location}/agents/{agent}/validationResult"
  };

  // The unique identifier of the agent validation result.
  // Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent
  // ID>/validationResult`.
  string name = 1;

  // Contains all flow validation results.
  repeated FlowValidationResult flow_validation_results = 2;
}
