// Copyright 2019 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.v2;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.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.V2";
option go_package = "google.golang.org/genproto/googleapis/cloud/dialogflow/v2;dialogflow";
option java_multiple_files = true;
option java_outer_classname = "AgentProto";
option java_package = "com.google.cloud.dialogflow.v2";
option objc_class_prefix = "DF";

// 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.v2.Intents], [Contexts][google.cloud.dialogflow.v2.Contexts],
// [Entity Types][google.cloud.dialogflow.v2.EntityTypes], [Webhooks][google.cloud.dialogflow.v2.WebhookRequest], and so on to
// manage the flow of a conversation and match user input to predefined intents
// and actions.
//
// You can create an agent using both Dialogflow Standard Edition and
// Dialogflow Enterprise Edition. For details, see
// [Dialogflow
// Editions](https://cloud.google.com/dialogflow/docs/editions).
//
// You can save your agent for backup or versioning by exporting the agent by
// using the [ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent] method. You can import a saved
// agent by using the [ImportAgent][google.cloud.dialogflow.v2.Agents.ImportAgent] method.
//
// Dialogflow provides several
// [prebuilt
// agents](https://cloud.google.com/dialogflow/docs/agents-prebuilt)
// for common conversation scenarios such as determining a date and time,
// converting currency, and so on.
//
// For more information about agents, see the
// [Dialogflow
// documentation](https://cloud.google.com/dialogflow/docs/agents-overview).
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";

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

  // Creates/updates the specified agent.
  rpc SetAgent(SetAgentRequest) returns (Agent) {
    option (google.api.http) = {
      post: "/v2/{agent.parent=projects/*}/agent"
      body: "agent"
    };
    option (google.api.method_signature) = "agent";
  }

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

  // Returns the list of agents.
  //
  // Since there is at most one conversational agent per project, this method is
  // useful primarily for listing all agents across projects the caller has
  // access to. One can achieve that with a wildcard project collection id "-".
  // Refer to [List
  // Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
  rpc SearchAgents(SearchAgentsRequest) returns (SearchAgentsResponse) {
    option (google.api.http) = {
      get: "/v2/{parent=projects/*}/agent:search"
    };
    option (google.api.method_signature) = "parent";
  }

  // Trains the specified agent.
  //
  // Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
  rpc TrainAgent(TrainAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/agent:train"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "google.protobuf.Struct"
    };
  }

  // Exports the specified agent to a ZIP file.
  //
  // Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse]>
  rpc ExportAgent(ExportAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/agent:export"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.dialogflow.v2.ExportAgentResponse"
      metadata_type: "google.protobuf.Struct"
    };
  }

  // Imports the specified agent from a ZIP file.
  //
  // Uploads new intents and entity types without deleting the existing ones.
  // Intents and entity types with the same name are replaced with the new
  // versions from ImportAgentRequest.
  //
  // Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
  rpc ImportAgent(ImportAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/agent:import"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "google.protobuf.Struct"
    };
  }

  // Restores the specified agent from a ZIP file.
  //
  // Replaces the current agent version with a new one. All the intents and
  // entity types in the older version are deleted.
  //
  // Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
  rpc RestoreAgent(RestoreAgentRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/agent:restore"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "google.protobuf.Struct"
    };
  }
}

// Represents a conversational agent.
message Agent {
  option (google.api.resource) = {
    type: "dialogflow.googleapis.com/Agent"
    pattern: "projects/{project}/agent"
  };

  // Match mode determines how intents are detected from user queries.
  enum MatchMode {
    // Not specified.
    MATCH_MODE_UNSPECIFIED = 0;

    // Best for agents with a small number of examples in intents and/or wide
    // use of templates syntax and composite entities.
    MATCH_MODE_HYBRID = 1;

    // Can be used for agents with a large number of examples in intents,
    // especially the ones using @sys.any or very large custom entities.
    MATCH_MODE_ML_ONLY = 2;
  }

  // API version for the agent.
  enum ApiVersion {
    // Not specified.
    API_VERSION_UNSPECIFIED = 0;

    // Legacy V1 API.
    API_VERSION_V1 = 1;

    // V2 API.
    API_VERSION_V2 = 2;

    // V2beta1 API.
    API_VERSION_V2_BETA_1 = 3;
  }

  // Represents the agent tier.
  enum Tier {
    // Not specified. This value should never be used.
    TIER_UNSPECIFIED = 0;

    // Standard tier.
    TIER_STANDARD = 1;

    // Enterprise tier (Essentials).
    TIER_ENTERPRISE = 2;

    // Enterprise tier (Plus).
    TIER_ENTERPRISE_PLUS = 3;
  }

  // Required. The project of this agent.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];

  // Required. The name of this agent.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

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

  // Optional. The list of all languages supported by this agent (except for the
  // `default_language_code`).
  repeated string supported_language_codes = 4 [(google.api.field_behavior) = OPTIONAL];

  // Required. The time zone of this 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];

  // Optional. The description of this agent.
  // The maximum length is 500 characters. If exceeded, the request is rejected.
  string description = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. 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 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Determines whether this agent should log conversation queries.
  bool enable_logging = 8 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Determines how intents are detected from user queries.
  MatchMode match_mode = 9 [(google.api.field_behavior) = OPTIONAL];

  // Optional. To filter out false positive results and still get variety in
  // matched natural language inputs for your agent, you can tune the machine
  // learning classification threshold. If the returned score value is less than
  // the threshold value, then a fallback intent will be triggered or, if there
  // are no fallback intents defined, no intent will be triggered. The score
  // values range from 0.0 (completely uncertain) to 1.0 (completely certain).
  // If set to 0.0, the default of 0.3 is used.
  float classification_threshold = 10 [(google.api.field_behavior) = OPTIONAL];

  // Optional. API version displayed in Dialogflow console. If not specified,
  // V2 API is assumed. Clients are free to query different service endpoints
  // for different API versions. However, bots connectors and webhook calls will
  // follow the specified API version.
  ApiVersion api_version = 14 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The agent tier. If not specified, TIER_STANDARD is assumed.
  Tier tier = 15 [(google.api.field_behavior) = OPTIONAL];
}

// The request message for [Agents.GetAgent][google.cloud.dialogflow.v2.Agents.GetAgent].
message GetAgentRequest {
  // Required. The project that the agent to fetch is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];
}

// The request message for [Agents.SetAgent][google.cloud.dialogflow.v2.Agents.SetAgent].
message SetAgentRequest {
  // Required. The agent to update.
  Agent agent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The mask to control which fields get updated.
  google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = OPTIONAL];
}

// The request message for [Agents.DeleteAgent][google.cloud.dialogflow.v2.Agents.DeleteAgent].
message DeleteAgentRequest {
  // Required. The project that the agent to delete is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];
}

// The request message for [Agents.SearchAgents][google.cloud.dialogflow.v2.Agents.SearchAgents].
message SearchAgentsRequest {
  // Required. The project to list agents from.
  // Format: `projects/<Project ID or '-'>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];

  // Optional. The maximum number of items to return in a single page. By
  // default 100 and at most 1000.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

// The response message for [Agents.SearchAgents][google.cloud.dialogflow.v2.Agents.SearchAgents].
message SearchAgentsResponse {
  // 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.TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent].
message TrainAgentRequest {
  // Required. The project that the agent to train is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];
}

// The request message for [Agents.ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent].
message ExportAgentRequest {
  // Required. The project that the agent to export is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];

  // Required. 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) = REQUIRED];
}

// The response message for [Agents.ExportAgent][google.cloud.dialogflow.v2.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`.
    string agent_uri = 1;

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

// The request message for [Agents.ImportAgent][google.cloud.dialogflow.v2.Agents.ImportAgent].
message ImportAgentRequest {
  // Required. The project that the agent to import is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];

  // Required. The agent to import.
  oneof agent {
    // The URI to a Google Cloud Storage file containing the agent to import.
    // Note: The URI must start with "gs://".
    string agent_uri = 2;

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

// The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2.Agents.RestoreAgent].
message RestoreAgentRequest {
  // Required. The project that the agent to restore is associated with.
  // Format: `projects/<Project ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "cloudresourcemanager.googleapis.com/Project"
    }
  ];

  // Required. The agent to restore.
  oneof agent {
    // The URI to a Google Cloud Storage file containing the agent to restore.
    // Note: The URI must start with "gs://".
    string agent_uri = 2;

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