// 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.discoveryengine.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/discoveryengine/v1/user_license.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.DiscoveryEngine.V1";
option go_package = "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb;discoveryenginepb";
option java_multiple_files = true;
option java_outer_classname = "UserLicenseServiceProto";
option java_package = "com.google.cloud.discoveryengine.v1";
option objc_class_prefix = "DISCOVERYENGINE";
option php_namespace = "Google\\Cloud\\DiscoveryEngine\\V1";
option ruby_package = "Google::Cloud::DiscoveryEngine::V1";

// Service for managing User Licenses.
service UserLicenseService {
  option (google.api.default_host) = "discoveryengine.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Lists the User Licenses.
  rpc ListUserLicenses(ListUserLicensesRequest)
      returns (ListUserLicensesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*/userStores/*}/userLicenses"
    };
    option (google.api.method_signature) = "parent";
  }

  // Updates the User License.
  // This method is used for batch assign/unassign licenses to users.
  rpc BatchUpdateUserLicenses(BatchUpdateUserLicensesRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/userStores/*}:batchUpdateUserLicenses"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.discoveryengine.v1.BatchUpdateUserLicensesResponse"
      metadata_type: "google.cloud.discoveryengine.v1.BatchUpdateUserLicensesMetadata"
    };
  }
}

// Request message for
// [UserLicenseService.ListUserLicenses][google.cloud.discoveryengine.v1.UserLicenseService.ListUserLicenses].
message ListUserLicensesRequest {
  // Required. The parent [UserStore][] resource name, format:
  // `projects/{project}/locations/{location}/userStores/{user_store_id}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/UserStore"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, defaults to 10. The maximum value is 50; values
  // above 50 will be coerced to 50.
  //
  // If this field is negative, an INVALID_ARGUMENT error is returned.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListUserLicenses` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListUserLicenses`
  // must match the call that provided the page token.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filter for the list request.
  //
  // Supported fields:
  //
  // * `license_assignment_state`
  //
  // Examples:
  //
  // * `license_assignment_state = ASSIGNED` to list assigned user licenses.
  // * `license_assignment_state = NO_LICENSE` to list not licensed users.
  // * `license_assignment_state = NO_LICENSE_ATTEMPTED_LOGIN` to list users
  // who attempted login but no license assigned.
  // * `license_assignment_state != NO_LICENSE_ATTEMPTED_LOGIN` to filter
  // out users who attempted login but no license assigned.
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for
// [UserLicenseService.ListUserLicenses][google.cloud.discoveryengine.v1.UserLicenseService.ListUserLicenses].
message ListUserLicensesResponse {
  // All the customer's
  // [UserLicense][google.cloud.discoveryengine.v1.UserLicense]s.
  repeated UserLicense user_licenses = 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;
}

// Request message for
// [UserLicenseService.BatchUpdateUserLicenses][google.cloud.discoveryengine.v1.UserLicenseService.BatchUpdateUserLicenses]
// method.
message BatchUpdateUserLicensesRequest {
  // The inline source for the input config for BatchUpdateUserLicenses
  // method.
  message InlineSource {
    // Required. A list of user licenses to update. Each user license
    // must have a valid
    // [UserLicense.user_principal][google.cloud.discoveryengine.v1.UserLicense.user_principal].
    repeated UserLicense user_licenses = 1
        [(google.api.field_behavior) = REQUIRED];

    // Optional. The list of fields to update.
    google.protobuf.FieldMask update_mask = 2
        [(google.api.field_behavior) = OPTIONAL];
  }

  // Required. The source of the input.
  oneof source {
    // The inline source for the input content for document embeddings.
    InlineSource inline_source = 2;
  }

  // Required. The parent [UserStore][] resource name, format:
  // `projects/{project}/locations/{location}/userStores/{user_store_id}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "discoveryengine.googleapis.com/UserStore"
    }
  ];

  // Optional. If true, if user licenses removed associated license config, the
  // user license will be deleted. By default which is false, the user license
  // will be updated to unassigned state.
  bool delete_unassigned_user_licenses = 4
      [(google.api.field_behavior) = OPTIONAL];
}

// Metadata related to the progress of the
// [UserLicenseService.BatchUpdateUserLicenses][google.cloud.discoveryengine.v1.UserLicenseService.BatchUpdateUserLicenses]
// operation. This will be returned by the google.longrunning.Operation.metadata
// field.
message BatchUpdateUserLicensesMetadata {
  // Operation create time.
  google.protobuf.Timestamp create_time = 1;

  // Operation last update time. If the operation is done, this is also the
  // finish time.
  google.protobuf.Timestamp update_time = 2;

  // Count of user licenses successfully updated.
  int64 success_count = 3;

  // Count of user licenses that failed to be updated.
  int64 failure_count = 4;
}

// Response message for
// [UserLicenseService.BatchUpdateUserLicenses][google.cloud.discoveryengine.v1.UserLicenseService.BatchUpdateUserLicenses]
// method.
message BatchUpdateUserLicensesResponse {
  // UserLicenses successfully updated.
  repeated UserLicense user_licenses = 1;

  // A sample of errors encountered while processing the request.
  repeated google.rpc.Status error_samples = 2;
}
