// 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 = "InstanceProto";
option java_package = "com.google.cloud.financialservices.v1";
option php_namespace = "Google\\Cloud\\FinancialServices\\V1";
option ruby_package = "Google::Cloud::FinancialServices::V1";

// Instance is a container for the rest of API resources.
// Only resources in the same instance can interact with each other.
// Child resources inherit the location (data residency) and encryption (CMEK).
// The location of the provided input and output in requests must match the
// location of the instance.
message Instance {
  option (google.api.resource) = {
    type: "financialservices.googleapis.com/Instance"
    pattern: "projects/{project}/locations/{location}/instances/{instance}"
  };

  // The Resource State
  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 full path to the Instance resource in this API.
  // format: `projects/{project}/locations/{location}/instances/{instance}`
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when the Instance was created.
  // Assigned by the server.
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when the Instance was last updated.
  // Assigned by the server.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. State of the instance.
  // Assigned by the server.
  State state = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

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

  // Required. The KMS key name used for CMEK (encryption-at-rest).
  // format:
  // `projects/{project}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{cryptoKey}`
  // VPC-SC restrictions apply.
  string kms_key = 6 [(google.api.field_behavior) = REQUIRED];
}

// Request for retrieving a paginated list of Instance resources that meet the
// specified criteria.
message ListInstancesRequest {
  // Required. The parent of the Instance is the location for that Instance.
  // Every location has exactly one instance.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // 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 ListInstancesResponse. It should be copied here to retrieve the
  // next page of resources. This will be empty for the first instance of
  // ListInstancesRequest.
  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 Instances
message ListInstancesResponse {
  // List of Instance resources
  repeated Instance instances = 1;

  // This token should be passed to the next ListInstancesRequest to retrieve
  // the next page of Instances.
  string next_page_token = 2;

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

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

// Request for creating a Instance resource.
message CreateInstanceRequest {
  // Required. The parent of the Instance is the location for that Instance.
  // Every location has exactly one instance.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

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

  // Required. The instance that will be created.
  Instance instance = 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 Instance
message UpdateInstanceRequest {
  // Optional. Field mask is used to specify the fields to be overwritten in the
  // Instance 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 instance fields that will be updated
  // according to the update_mask
  Instance instance = 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 Instance.
message DeleteInstanceRequest {
  // Required. The resource name of the Instance.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Instance"
    }
  ];

  // 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 adding/removing registered parties from BigQuery tables
// specified by the customer.
message ImportRegisteredPartiesRequest {
  // UpdateMode controls the behavior for ImportRegisteredParties.
  enum UpdateMode {
    // Default mode.
    UPDATE_MODE_UNSPECIFIED = 0;

    // Replace parties that are removable in Parties Table with new parties.
    REPLACE = 1;

    // Add new parties to Parties Table.
    APPEND = 2;
  }

  // Required. The full path to the Instance resource in this API.
  // format: `projects/{project}/locations/{location}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Instance"
    }
  ];

  // Optional. List of BigQuery tables. Union of tables will be taken if there
  // is more than one table. VPC-SC restrictions apply. format:
  // `bq://{project}.{bqDatasetID}.{bqTableID}` Use of `datasets` is preferred
  // over the latter due to its simplicity and the reduced risk of errors
  // `party_tables` and `datasets` must not be provided at the
  // same time
  repeated string party_tables = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. Mode of the request.
  UpdateMode mode = 3 [(google.api.field_behavior) = REQUIRED];

  // Optional. If the request will not register the parties, just determine what
  // would happen.
  bool validate_only = 4 [(google.api.field_behavior) = OPTIONAL];

  // Required. LineOfBusiness for the specified registered parties.
  LineOfBusiness line_of_business = 5 [(google.api.field_behavior) = REQUIRED];
}

// Response for adding/removing registered parties from BigQuery tables.
message ImportRegisteredPartiesResponse {
  // Number of parties added by this operation.
  int64 parties_added = 1;

  // Number of parties removed by this operation.
  int64 parties_removed = 2;

  // Total number of parties that are registered in this instance, after the
  // update operation was completed.
  int64 parties_total = 3;

  // Number of parties that failed to be removed by this operation.
  int64 parties_failed_to_remove = 4;

  int64 parties_uptiered = 5;

  // Total number of parties that are downtiered in this instance
  int64 parties_downtiered = 6;

  // Number of parties that failed to be downtiered
  int64 parties_failed_to_downtier = 7;
}

// Request to export a list of currently registered parties.
message ExportRegisteredPartiesRequest {
  // Required. The full path to the Instance resource in this API.
  // format: `projects/{project}/locations/{location}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "financialservices.googleapis.com/Instance"
    }
  ];

  // Required. The location to output the RegisteredParties.
  BigQueryDestination dataset = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. LineOfBusiness to get RegisteredParties from.
  LineOfBusiness line_of_business = 3 [(google.api.field_behavior) = REQUIRED];
}

// Response to export registered parties request.
message ExportRegisteredPartiesResponse {}
