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

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/resource.proto";
import "google/cloud/licensemanager/v1/api_entities.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.LicenseManager.V1";
option go_package = "cloud.google.com/go/licensemanager/apiv1/licensemanagerpb;licensemanagerpb";
option java_multiple_files = true;
option java_outer_classname = "LicenseManagerProto";
option java_package = "com.google.cloud.licensemanager.v1";
option php_namespace = "Google\\Cloud\\LicenseManager\\V1";
option ruby_package = "Google::Cloud::LicenseManager::V1";
option (google.api.resource_definition) = {
  type: "compute.googleapis.com/ComputeInstance"
  pattern: "projects/{project}/zones/{zone}/instances/{instance}"
};

// Service describing handlers for resources
service LicenseManager {
  option (google.api.default_host) = "licensemanager.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Lists Configurations in a given project and location.
  rpc ListConfigurations(ListConfigurationsRequest)
      returns (ListConfigurationsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/configurations"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single Configuration.
  rpc GetConfiguration(GetConfigurationRequest) returns (Configuration) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/configurations/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a new Configuration in a given project and location.
  rpc CreateConfiguration(CreateConfigurationRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/configurations"
      body: "configuration"
    };
    option (google.api.method_signature) =
        "parent,configuration,configuration_id";
    option (google.longrunning.operation_info) = {
      response_type: "Configuration"
      metadata_type: "OperationMetadata"
    };
  }

  // Updates the parameters of a single Configuration.
  rpc UpdateConfiguration(UpdateConfigurationRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      patch: "/v1/{configuration.name=projects/*/locations/*/configurations/*}"
      body: "configuration"
    };
    option (google.api.method_signature) = "configuration,update_mask";
    option (google.longrunning.operation_info) = {
      response_type: "Configuration"
      metadata_type: "OperationMetadata"
    };
  }

  // Deletes a single Configuration.
  rpc DeleteConfiguration(DeleteConfigurationRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/configurations/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "OperationMetadata"
    };
  }

  // Lists Instances in a given project and location.
  rpc ListInstances(ListInstancesRequest) returns (ListInstancesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/instances"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single Instance.
  rpc GetInstance(GetInstanceRequest) returns (Instance) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/instances/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Deactivates the given configuration.
  rpc DeactivateConfiguration(DeactivateConfigurationRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/configurations/*}:deactivate"
      body: "*"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "Configuration"
      metadata_type: "OperationMetadata"
    };
  }

  // Reactivates the given configuration.
  rpc ReactivateConfiguration(ReactivateConfigurationRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/configurations/*}:reactivate"
      body: "*"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "Configuration"
      metadata_type: "OperationMetadata"
    };
  }

  // License Usage information for a Configuration.
  rpc QueryConfigurationLicenseUsage(QueryConfigurationLicenseUsageRequest)
      returns (QueryConfigurationLicenseUsageResponse) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/configurations/*}:queryLicenseUsage"
    };
    option (google.api.method_signature) = "name,start_time,end_time";
  }

  // Aggregates Usage per Instance for a Configuration.
  rpc AggregateUsage(AggregateUsageRequest) returns (AggregateUsageResponse) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/configurations/*}:aggregateUsage"
    };
    option (google.api.method_signature) = "name,start_time,end_time";
  }

  // Lists Products in a given project and location.
  rpc ListProducts(ListProductsRequest) returns (ListProductsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/products"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single Product.
  rpc GetProduct(GetProductRequest) returns (Product) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/products/*}"
    };
    option (google.api.method_signature) = "name";
  }
}

// Message for requesting list of Configurations
message ListConfigurationsRequest {
  // Required. Parent value for ListConfigurationsRequest
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A token identifying a page of results the server should return.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filtering results
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hint for how to order the results
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Message for response to listing Configurations
message ListConfigurationsResponse {
  // The list of Configuration
  repeated Configuration configurations = 1;

  // A token identifying a page of results the server should return.
  string next_page_token = 2;

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

// Message for getting a Configuration
message GetConfigurationRequest {
  // Required. Name of the resource
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];
}

// Message for creating a Configuration
message CreateConfigurationRequest {
  // Required. Value for parent.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // Required. Id of the requesting object
  string configuration_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The resource being created
  Configuration configuration = 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_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Message for updating a Configuration
message UpdateConfigurationRequest {
  // Optional. Field mask is used to specify the fields to be overwritten in the
  // Configuration 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 resource being updated
  Configuration configuration = 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_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Message for deleting a Configuration
message DeleteConfigurationRequest {
  // Required. Name of the resource
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // 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_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Message for requesting list of Instances
message ListInstancesRequest {
  // Required. Parent value for ListInstancesRequest
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "licensemanager.googleapis.com/Instance"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A token identifying a page of results the server should return.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filtering results
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hint for how to order the results
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Message for response to listing Instances
message ListInstancesResponse {
  // The list of Instance
  repeated Instance instances = 1;

  // A token identifying a page of results the server should return.
  string next_page_token = 2;

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

// Message for getting a Instance
message GetInstanceRequest {
  // Required. Name of the resource
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Instance"
    }
  ];
}

// Message for requesting license usage per configuration.
message QueryConfigurationLicenseUsageRequest {
  // Required. The resource path of the Configuration.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // Required. The start time for retrieving the usage. If not specified, we
  // will use the first day of the current billing period.
  google.protobuf.Timestamp start_time = 2
      [(google.api.field_behavior) = REQUIRED];

  // Required. The end time for retrieving the usage. If not specified, we will
  // use the last day of the current billing period.
  google.protobuf.Timestamp end_time = 3
      [(google.api.field_behavior) = REQUIRED];
}

// Message for response to get the license usage per configuration.
message QueryConfigurationLicenseUsageResponse {
  // Depending on the type of the configuration, one of the following
  // will be populated.
  oneof details {
    // Usage information for license types which use user-count billing.
    UserCountUsage user_count_usage = 1;
  }
}

// Message for deactivating a Configuration.
message DeactivateConfigurationRequest {
  // Required. Name of the resource.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // 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_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Message for resuming a Configuration.
message ReactivateConfigurationRequest {
  // Required. Name of the resource.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // 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_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Message for requesting aggregate of Usage per configuration.
message AggregateUsageRequest {
  // Required. Parent value for AggregateUsageRequest
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Configuration"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A token identifying a page of results the server should return.
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filtering results
  string filter = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hint for how to order the results
  string order_by = 6 [(google.api.field_behavior) = OPTIONAL];

  // Required. Licenses are purchased per month - so usage track needs start
  // time of a month.
  google.protobuf.Timestamp start_time = 7
      [(google.api.field_behavior) = REQUIRED];

  // Required. Usage track is always for a month. This parameter is for the end
  // time of the month.
  google.protobuf.Timestamp end_time = 8
      [(google.api.field_behavior) = REQUIRED];
}

// Message for response for aggregating usage count
message AggregateUsageResponse {
  // The aggregated records of usage per configuration
  repeated Usage usages = 1;

  // A token identifying a page of results the server should return.
  string next_page_token = 2;

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

// Message for requesting list of Products
message ListProductsRequest {
  // Required. Parent value for ListProductsRequest
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "licensemanager.googleapis.com/Product"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A token identifying a page of results the server should return.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filtering results
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Hint for how to order the results
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Message for response to listing Products
message ListProductsResponse {
  // The list of Product
  repeated Product products = 1;

  // A token identifying a page of results the server should return.
  string next_page_token = 2;

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

// Message for getting a Product
message GetProductRequest {
  // Required. Name of the resource
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Product"
    }
  ];
}

// Represents the metadata of the long-running operation.
message OperationMetadata {
  // 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. Server-defined resource path for the target of the operation.
  string target = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Name of the verb executed by the operation.
  string verb = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Human-readable status of the operation, if any.
  string status_message = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Identifies whether the user has requested cancellation
  // of the operation. Operations that have been cancelled successfully
  // have
  // [google.longrunning.Operation.error][google.longrunning.Operation.error]
  // value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`.
  bool requested_cancellation = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. API version used to start the operation.
  string api_version = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
}
