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

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/financialservices/v1/bigquery_destination.proto";
import "google/cloud/financialservices/v1/line_of_business.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.FinancialServices.V1";
option go_package = "cloud.google.com/go/financialservices/apiv1/financialservicespb;financialservicespb";
option java_multiple_files = true;
option java_outer_classname = "PredictionResultProto";
option java_package = "com.google.cloud.financialservices.v1";
option php_namespace = "Google\\Cloud\\FinancialServices\\V1";
option ruby_package = "Google::Cloud::FinancialServices::V1";

// PredictionResult is the result of using a model to create predictions.
message PredictionResult {
  option (google.api.resource) = {
    type: "financialservices.googleapis.com/PredictionResult"
    pattern: "projects/{project_num}/locations/{location}/instances/{instance}/predictionResults/{prediction_result}"
  };

  // Outputs is a list of places where the operation will write results.
  message Outputs {
    // Required. The location to output the predictions.
    BigQueryDestination prediction_destination = 1
        [(google.api.field_behavior) = REQUIRED];

    // The location to output explainability information.  If not specified
    // no explainability data will be output.
    BigQueryDestination explainability_destination = 2;
  }

  // The possible states of a resource.
  enum State {
    // State is unspecified, should not occur.
    STATE_UNSPECIFIED = 0;

    // The resource has not finished being created.
    CREATING = 1;

    // The resource is active/ready to be used.
    ACTIVE = 2;

    // The resource is in the process of being updated.
    UPDATING = 3;

    // The resource is in the process of being deleted.
    DELETING = 4;
  }

  // Output only. The resource name of the PredictionResult.
  // format:
  // `/projects/{project_num}/locations/{location}/instances/{instance}/predictionResults/{prediction_result}`
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp of creation of this resource.
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp of the most recent update of this resource.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Labels
  map<string, string> labels = 4;

  // Output only. State of the PredictionResult (creating, active, deleting,
  // etc.)
  State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. The resource name of the Dataset to do predictions on
  // Format:
  // `/projects/{project_num}/locations/{location}/instances/{instance}/dataset/{dataset_id}`
  string dataset = 6 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Dataset"
    }
  ];

  // Required. The resource name of the Model to use to use to make predictions
  // Format:
  // `/projects/{project_num}/locations/{location}/instances/{instance}/models/{model}`
  string model = 7 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Model"
    }
  ];

  // Required. Specifies the latest time from which data is used to generate
  // features for predictions.  This time should be no later than the end of the
  // [date_range][google.cloud.financialservices.v1.Dataset.date_range] of the
  // dataset.
  google.protobuf.Timestamp end_time = 9
      [(google.api.field_behavior) = REQUIRED];

  // The number of consecutive months to produce predictions for, ending with
  // the last full month prior to
  // [end_time][google.cloud.financialservices.v1.PredictionResult.end_time]
  // according to the dataset's timezone.
  int32 prediction_periods = 10;

  // Required. Where to write the output of the predictions.
  Outputs outputs = 11 [(google.api.field_behavior) = REQUIRED];

  // Output only. The line of business (Retail/Commercial) this prediction is
  // for. Determined by Model, cannot be set by user.
  LineOfBusiness line_of_business = 12
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request for retrieving a paginated list of PredictionResult resources that
// meet the specified criteria.
message ListPredictionResultsRequest {
  // Required. The parent of the PredictionResult is the Instance.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Instance"
    }
  ];

  // The number of resources to be included in the response. The response
  // contains a next_page_token, which can be used to retrieve the next page of
  // resources.
  int32 page_size = 2;

  // In case of paginated results, this is the token that was returned in the
  // previous ListPredictionResultsResponse. It should be copied here to
  // retrieve the next page of resources. Empty will give the first page of
  // ListPredictionResultsRequest, and the last page will return an empty
  // page_token.
  string page_token = 3;

  // Specify a filter to narrow search results.
  string filter = 4;

  // Specify a field to use for ordering.
  string order_by = 5;
}

// Response for retrieving a list of PredictionResults
message ListPredictionResultsResponse {
  // List of PredictionResult resources
  repeated PredictionResult prediction_results = 1;

  // This token should be passed to the next ListPredictionResultsRequest to
  // retrieve the next page of PredictionResults (empty indicicates we are
  // done).
  string next_page_token = 2;

  // Locations that could not be reached.
  repeated string unreachable = 3;
}

// Request for retrieving a specific PredictionResult resource.
message GetPredictionResultRequest {
  // Required. The resource name of the PredictionResult
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/PredictionResult"
    }
  ];
}

// Request for creating a PredictionResult resource.
message CreatePredictionResultRequest {
  // Required. The parent of the PredictionResult is the Instance.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Instance"
    }
  ];

  // Required. The resource id of the PredictionResult
  string prediction_result_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The PredictionResult that will be created.
  PredictionResult prediction_result = 3
      [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes since the first request.
  //
  // For example, consider a situation where you make an initial request and the
  // request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Request for updating a PredictionResult
message UpdatePredictionResultRequest {
  // Optional. Field mask is used to specify the fields to be overwritten in the
  // PredictionResult resource by the update.
  // The fields specified in the update_mask are relative to the resource, not
  // the full request. A field will be overwritten if it is in the mask. If the
  // user does not provide a mask then all fields will be overwritten.
  google.protobuf.FieldMask update_mask = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Required. The new value of the PredictionResult fields that will be updated
  // according to the update_mask.
  PredictionResult prediction_result = 2
      [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes since the first request.
  //
  // For example, consider a situation where you make an initial request and the
  // request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Request for deleting a PredictionResult.
message DeletePredictionResultRequest {
  // Required. The resource name of the PredictionResult.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/PredictionResult"
    }
  ];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes after the first request.
  //
  // For example, consider a situation where you make an initial request and the
  // request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 2 [(google.api.field_behavior) = OPTIONAL];
}

// Request for exporting PredictionResult metadata.
message ExportPredictionResultMetadataRequest {
  // Required. The resource name of the PredictionResult.
  string prediction_result = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/PredictionResult"
    }
  ];

  // Required. BigQuery output where the metadata will be written.
  BigQueryDestination structured_metadata_destination = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Response for exporting PredictionResult metadata.
message ExportPredictionResultMetadataResponse {}
