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

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/contactcenterinsights/v1/resources.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.ContactCenterInsights.V1";
option go_package = "google.golang.org/genproto/googleapis/cloud/contactcenterinsights/v1;contactcenterinsights";
option java_multiple_files = true;
option java_outer_classname = "ContactCenterInsightsProto";
option java_package = "com.google.cloud.contactcenterinsights.v1";
option php_namespace = "Google\\Cloud\\ContactCenterInsights\\V1";
option ruby_package = "Google::Cloud::ContactCenterInsights::V1";

// An API that lets users analyze and explore their business conversation data.
service ContactCenterInsights {
  option (google.api.default_host) = "contactcenterinsights.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";

  // Creates a conversation.
  rpc CreateConversation(CreateConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/conversations"
      body: "conversation"
    };
    option (google.api.method_signature) = "parent,conversation,conversation_id";
  }

  // Updates a conversation.
  rpc UpdateConversation(UpdateConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      patch: "/v1/{conversation.name=projects/*/locations/*/conversations/*}"
      body: "conversation"
    };
    option (google.api.method_signature) = "conversation,update_mask";
  }

  // Gets a conversation.
  rpc GetConversation(GetConversationRequest) returns (Conversation) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/conversations/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists conversations.
  rpc ListConversations(ListConversationsRequest) returns (ListConversationsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/conversations"
    };
    option (google.api.method_signature) = "parent";
  }

  // Deletes a conversation.
  rpc DeleteConversation(DeleteConversationRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/conversations/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates an analysis. The long running operation is done when the analysis
  // has completed.
  rpc CreateAnalysis(CreateAnalysisRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/conversations/*}/analyses"
      body: "analysis"
    };
    option (google.api.method_signature) = "parent,analysis";
    option (google.longrunning.operation_info) = {
      response_type: "Analysis"
      metadata_type: "CreateAnalysisOperationMetadata"
    };
  }

  // Gets an analysis.
  rpc GetAnalysis(GetAnalysisRequest) returns (Analysis) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/conversations/*/analyses/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists analyses.
  rpc ListAnalyses(ListAnalysesRequest) returns (ListAnalysesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*/conversations/*}/analyses"
    };
    option (google.api.method_signature) = "parent";
  }

  // Deletes an analysis.
  rpc DeleteAnalysis(DeleteAnalysisRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/conversations/*/analyses/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Export insights data to a destination defined in the request body.
  rpc ExportInsightsData(ExportInsightsDataRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/insightsdata:export"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
    option (google.longrunning.operation_info) = {
      response_type: "ExportInsightsDataResponse"
      metadata_type: "ExportInsightsDataMetadata"
    };
  }

  // Gets an issue model.
  rpc GetIssueModel(GetIssueModelRequest) returns (IssueModel) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/issueModels/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists issue models.
  rpc ListIssueModels(ListIssueModelsRequest) returns (ListIssueModelsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/issueModels"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets an issue.
  rpc GetIssue(GetIssueRequest) returns (Issue) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/issueModels/*/issues/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists issues.
  rpc ListIssues(ListIssuesRequest) returns (ListIssuesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*/issueModels/*}/issues"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets an issue model's statistics.
  rpc CalculateIssueModelStats(CalculateIssueModelStatsRequest) returns (CalculateIssueModelStatsResponse) {
    option (google.api.http) = {
      get: "/v1/{issue_model=projects/*/locations/*/issueModels/*}:calculateIssueModelStats"
    };
    option (google.api.method_signature) = "issue_model";
  }

  // Creates a phrase matcher.
  rpc CreatePhraseMatcher(CreatePhraseMatcherRequest) returns (PhraseMatcher) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/phraseMatchers"
      body: "phrase_matcher"
    };
    option (google.api.method_signature) = "parent,phrase_matcher";
  }

  // Gets a phrase matcher.
  rpc GetPhraseMatcher(GetPhraseMatcherRequest) returns (PhraseMatcher) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/phraseMatchers/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists phrase matchers.
  rpc ListPhraseMatchers(ListPhraseMatchersRequest) returns (ListPhraseMatchersResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/phraseMatchers"
    };
    option (google.api.method_signature) = "parent";
  }

  // Deletes a phrase matcher.
  rpc DeletePhraseMatcher(DeletePhraseMatcherRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/phraseMatchers/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Gets conversation statistics.
  rpc CalculateStats(CalculateStatsRequest) returns (CalculateStatsResponse) {
    option (google.api.http) = {
      get: "/v1/{location=projects/*/locations/*}/conversations:calculateStats"
    };
    option (google.api.method_signature) = "location";
  }

  // Gets project-level settings.
  rpc GetSettings(GetSettingsRequest) returns (Settings) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/settings}"
    };
    option (google.api.method_signature) = "name";
  }

  // Updates project-level settings.
  rpc UpdateSettings(UpdateSettingsRequest) returns (Settings) {
    option (google.api.http) = {
      patch: "/v1/{settings.name=projects/*/locations/*/settings}"
      body: "settings"
    };
    option (google.api.method_signature) = "settings,update_mask";
  }
}

// The request for calculating conversation statistics.
message CalculateStatsRequest {
  // Required. The location of the conversations.
  string location = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // A filter to reduce results to a specific subset. This field is useful for
  // getting statistics about conversations with specific properties.
  string filter = 2;
}

// Represents the options for views of a conversation.
enum ConversationView {
  // Not specified. Defaults to FULL on GetConversationRequest and BASIC for
  // ListConversationsRequest.
  CONVERSATION_VIEW_UNSPECIFIED = 0;

  // Transcript field is not populated in the response.
  BASIC = 1;

  // All fields are populated.
  FULL = 2;
}

// The response for calculating conversation statistics.
message CalculateStatsResponse {
  // A time series representing conversations over time.
  message TimeSeries {
    // A single interval in a time series.
    message Interval {
      // The start time of this interval.
      google.protobuf.Timestamp start_time = 1;

      // The number of conversations created in this interval.
      int32 conversation_count = 2;
    }

    // The duration of each interval.
    google.protobuf.Duration interval_duration = 1;

    // An ordered list of intervals from earliest to latest, where each interval
    // represents the number of conversations that transpired during the time
    // window.
    repeated Interval points = 2;
  }

  // The average duration of all conversations. The average is calculated using
  // only conversations that have a time duration.
  google.protobuf.Duration average_duration = 1;

  // The average number of turns per conversation.
  int32 average_turn_count = 2;

  // The total number of conversations.
  int32 conversation_count = 3;

  // A map associating each smart highlighter display name with its respective
  // number of matches in the set of conversations.
  map<string, int32> smart_highlighter_matches = 4;

  // A map associating each custom highlighter resource name with its respective
  // number of matches in the set of conversations.
  map<string, int32> custom_highlighter_matches = 5;

  // A map associating each issue resource name with its respective number of
  // matches in the set of conversations. Key has the format:
  // `projects/<Project ID>/locations/<Location ID>/issueModels/<Issue Model
  // ID>/issues/<Issue ID>`
  map<string, int32> issue_matches = 6;

  // A time series representing the count of conversations created over time
  // that match that requested filter criteria.
  TimeSeries conversation_count_time_series = 7;
}

// Metadata for a create analysis operation.
message CreateAnalysisOperationMetadata {
  // Output only. The time the operation was created.
  google.protobuf.Timestamp create_time = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

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

  // Output only. The Conversation that this Analysis Operation belongs to.
  string conversation = 3 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Conversation"
    }
  ];
}

// Request to create a conversation.
message CreateConversationRequest {
  // Required. The parent resource of the conversation.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Required. The conversation resource to create.
  Conversation conversation = 2 [(google.api.field_behavior) = REQUIRED];

  // A unique ID for the new conversation. This ID will become the final
  // component of the conversation's resource name. If no ID is specified, a
  // server-generated ID will be used.
  //
  // This value should be 4-32 characters and must match the regular
  // expression /^[a-z0-9-]{4,32}$/. Valid characters are /[a-z][0-9]-/
  string conversation_id = 3;
}

// Request to list conversations.
message ListConversationsRequest {
  // Required. The parent resource of the conversation.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // The maximum number of conversations to return in the response. If this
  // value is zero, the service will select a default size. A call might return
  // fewer objects than requested. A non-empty `next_page_token` in the response
  // indicates that more data is available.
  int32 page_size = 2;

  // The value returned by the last `ListConversationsResponse`. This value
  // indicates that this is a continuation of a prior `ListConversations` call
  // and that the system should return the next page of data.
  string page_token = 3;

  // A filter to reduce results to a specific subset. Useful for querying
  // conversations with specific properties.
  string filter = 4;

  // The level of details of the conversation. Default is `BASIC`.
  ConversationView view = 5;
}

// The response of listing conversations.
message ListConversationsResponse {
  // The conversations that match the request.
  repeated Conversation conversations = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// The request to get a conversation.
message GetConversationRequest {
  // Required. The name of the conversation to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Conversation"
    }
  ];

  // The level of details of the conversation. Default is `FULL`.
  ConversationView view = 2;
}

// The request to update a conversation.
message UpdateConversationRequest {
  // Required. The new values for the conversation.
  Conversation conversation = 1 [(google.api.field_behavior) = REQUIRED];

  // The list of fields to be updated.
  google.protobuf.FieldMask update_mask = 2;
}

// The request to delete a conversation.
message DeleteConversationRequest {
  // Required. The name of the conversation to delete.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Conversation"
    }
  ];

  // If set to true, all of this conversation's analyses will also be deleted.
  // Otherwise, the request will only succeed if the conversation has no
  // analyses.
  bool force = 2;
}

// The request to create an analysis.
message CreateAnalysisRequest {
  // Required. The parent resource of the analysis.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Conversation"
    }
  ];

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

// The request to list analyses.
message ListAnalysesRequest {
  // Required. The parent resource of the analyses.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Conversation"
    }
  ];

  // The maximum number of analyses to return in the response. If this
  // value is zero, the service will select a default size. A call might return
  // fewer objects than requested. A non-empty `next_page_token` in the response
  // indicates that more data is available.
  int32 page_size = 2;

  // The value returned by the last `ListAnalysesResponse`; indicates
  // that this is a continuation of a prior `ListAnalyses` call and
  // the system should return the next page of data.
  string page_token = 3;

  // A filter to reduce results to a specific subset. Useful for querying
  // conversations with specific properties.
  string filter = 4;
}

// The response to list analyses.
message ListAnalysesResponse {
  // The analyses that match the request.
  repeated Analysis analyses = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// The request to get an analysis.
message GetAnalysisRequest {
  // Required. The name of the analysis to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Analysis"
    }
  ];
}

// The request to delete an analysis.
message DeleteAnalysisRequest {
  // Required. The name of the analysis to delete.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Analysis"
    }
  ];
}

// The request to export insights.
message ExportInsightsDataRequest {
  // A BigQuery Table Reference.
  message BigQueryDestination {
    // A project ID or number. If specified, then export will attempt to
    // write data to this project instead of the resource project. Otherwise,
    // the resource project will be used.
    string project_id = 3;

    // Required. The name of the BigQuery dataset that the snapshot result should be
    // exported to. If this dataset does not exist, the export call returns an
    // INVALID_ARGUMENT error.
    string dataset = 1 [(google.api.field_behavior) = REQUIRED];

    // The BigQuery table name to which the insights data should be written.
    // If this table does not exist, the export call returns an INVALID_ARGUMENT
    // error.
    string table = 2;
  }

  // Exporter destination.
  oneof destination {
    // Specified if sink is a BigQuery table.
    BigQueryDestination big_query_destination = 2;
  }

  // Required. The parent resource to export data from.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // A filter to reduce results to a specific subset. Useful for exporting
  // conversations with specific properties.
  string filter = 3;

  // A fully qualified KMS key name for BigQuery tables protected by CMEK.
  // Format:
  // projects/{project}/locations/{location}/keyRings/{keyring}/cryptoKeys/{key}/cryptoKeyVersions/{version}
  string kms_key = 4;
}

// Metadata for an export insights operation.
message ExportInsightsDataMetadata {
  // Output only. The time the operation was created.
  google.protobuf.Timestamp create_time = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

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

  // The original request for export.
  ExportInsightsDataRequest request = 3;

  // Partial errors during export operation that might cause the operation
  // output to be incomplete.
  repeated google.rpc.Status partial_errors = 4;
}

// Response for an export insights operation.
message ExportInsightsDataResponse {

}

// Request to list issue models.
message ListIssueModelsRequest {
  // Required. The parent resource of the issue model.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];
}

// The response of listing issue models.
message ListIssueModelsResponse {
  // The issue models that match the request.
  repeated IssueModel issue_models = 1;
}

// The request to get an issue model.
message GetIssueModelRequest {
  // Required. The name of the issue model to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/IssueModel"
    }
  ];
}

// The request to get an issue.
message GetIssueRequest {
  // Required. The name of the issue to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Issue"
    }
  ];
}

// Request to list issues.
message ListIssuesRequest {
  // Required. The parent resource of the issue.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/IssueModel"
    }
  ];
}

// The response of listing issues.
message ListIssuesResponse {
  // The issues that match the request.
  repeated Issue issues = 1;
}

// Request to get statistics of an issue model.
message CalculateIssueModelStatsRequest {
  // Required. The resource name of the issue model to query against.
  string issue_model = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/IssueModel"
    }
  ];
}

// Response of querying an issue model's statistics.
message CalculateIssueModelStatsResponse {
  // The latest label statistics for the queried issue model. Includes results
  // on both training data and data labeled after deployment.
  IssueModelLabelStats current_stats = 4;
}

// Request to create a phrase matcher.
message CreatePhraseMatcherRequest {
  // Required. The parent resource of the phrase matcher. Required. The location to create
  // a phrase matcher for.
  // Format: `projects/<Project ID>/locations/<Location ID>` or
  // `projects/<Project Number>/locations/<Location ID>`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Required. The phrase matcher resource to create.
  PhraseMatcher phrase_matcher = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request to list phrase matchers.
message ListPhraseMatchersRequest {
  // Required. The parent resource of the phrase matcher.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // The maximum number of phrase matchers to return in the response. If this
  // value is zero, the service will select a default size. A call might return
  // fewer objects than requested. A non-empty `next_page_token` in the response
  // indicates that more data is available.
  int32 page_size = 2;

  // The value returned by the last `ListPhraseMatchersResponse`. This value
  // indicates that this is a continuation of a prior `ListPhraseMatchers` call
  // and that the system should return the next page of data.
  string page_token = 3;

  // A filter to reduce results to a specific subset. Useful for querying
  // phrase matchers with specific properties.
  string filter = 4;
}

// The response of listing phrase matchers.
message ListPhraseMatchersResponse {
  // The phrase matchers that match the request.
  repeated PhraseMatcher phrase_matchers = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// The request to get a a phrase matcher.
message GetPhraseMatcherRequest {
  // Required. The name of the phrase matcher to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/PhraseMatcher"
    }
  ];
}

// The request to delete a phrase matcher.
message DeletePhraseMatcherRequest {
  // Required. The name of the phrase matcher to delete.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/PhraseMatcher"
    }
  ];
}

// The request to get project-level settings.
message GetSettingsRequest {
  // Required. The name of the settings resource to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "contactcenterinsights.googleapis.com/Settings"
    }
  ];
}

// The request to update project-level settings.
message UpdateSettingsRequest {
  // Required. The new values for the conversation.
  Settings settings = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The list of fields to be updated.
  google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED];
}
