// 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/field_behavior.proto";
import "google/api/resource.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 = "ApiEntitiesProto";
option java_package = "com.google.cloud.licensemanager.v1";
option php_namespace = "Google\\Cloud\\LicenseManager\\V1";
option ruby_package = "Google::Cloud::LicenseManager::V1";

// Different types of licenses that are supported.
enum LicenseType {
  // unspecified.
  LICENSE_TYPE_UNSPECIFIED = 0;

  // Billing will be based on number of users listed per month.
  LICENSE_TYPE_PER_MONTH_PER_USER = 1;

  // Bring your own license.
  LICENSE_TYPE_BRING_YOUR_OWN_LICENSE = 2;
}

// State of the License Key activation on the instance.
enum ActivationState {
  // The Status of the activation is unspecified
  ACTIVATION_STATE_UNSPECIFIED = 0;

  // Activation key (MAK) requested for the instance.
  ACTIVATION_STATE_KEY_REQUESTED = 1;

  // License activation process is running on the instance.
  ACTIVATION_STATE_ACTIVATING = 2;

  // License activation is complete on the instance.
  ACTIVATION_STATE_ACTIVATED = 3;

  // License Key is deactivating on the instance.
  ACTIVATION_STATE_DEACTIVATING = 4;

  // License Key is deactivated on the instance.
  ACTIVATION_STATE_DEACTIVATED = 5;

  // License Key activation failed on the instance.
  ACTIVATION_STATE_TERMINATED = 6;
}

// Configuration for a Google SPLA product
message Configuration {
  option (google.api.resource) = {
    type: "licensemanager.googleapis.com/Configuration"
    pattern: "projects/{project}/locations/{location}/configurations/{configuration}"
    plural: "configurations"
    singular: "configuration"
  };

  // State of the configuration.
  enum State {
    // The Status of the configuration is unspecified
    STATE_UNSPECIFIED = 0;

    // Configuration is in active state.
    STATE_ACTIVE = 1;

    // Configuration is in deactivated state.
    STATE_SUSPENDED = 2;

    // Configuration is in deleted state.
    STATE_DELETED = 3;
  }

  // Identifier. name of resource
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. User given name.
  string display_name = 5 [(google.api.field_behavior) = REQUIRED];

  // Required. Name field (with URL) of the Product offered for SPLA.
  string product = 6 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "licensemanager.googleapis.com/Product"
    }
  ];

  // Required. LicenseType to be applied for billing
  LicenseType license_type = 7 [(google.api.field_behavior) = REQUIRED];

  // Required. Billing information applicable till end of the current month.
  BillingInfo current_billing_info = 8 [(google.api.field_behavior) = REQUIRED];

  // Required. Billing information applicable for next month.
  BillingInfo next_billing_info = 9 [(google.api.field_behavior) = REQUIRED];

  // Output only. [Output only] Create time stamp
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. [Output only] Update time stamp
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. Labels as key value pairs
  map<string, string> labels = 4 [(google.api.field_behavior) = OPTIONAL];

  // Output only. State of the configuration.
  State state = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Billing Information.
message BillingInfo {
  oneof current_billing_info {
    // Required. This type of billing uses user count for computing total
    // charge.
    UserCountBillingInfo user_count_billing = 1
        [(google.api.field_behavior) = REQUIRED];
  }

  // Output only. When the billing starts.
  google.protobuf.Timestamp start_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. When the billing ends.
  google.protobuf.Timestamp end_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// This approach uses total unique user count for billing.
message UserCountBillingInfo {
  // Required. Number of users to bill for.
  int32 user_count = 1 [(google.api.field_behavior) = REQUIRED];
}

// Message representing usage for license configurations which use user-count
// billing.
message UserCountUsage {
  // Required. Unique number of licensed users.
  int32 unique_user_count = 1 [(google.api.field_behavior) = REQUIRED];
}

// Products for Google SPLA.
message Product {
  option (google.api.resource) = {
    type: "licensemanager.googleapis.com/Product"
    pattern: "projects/{project}/locations/{location}/products/{product}"
    plural: "products"
    singular: "product"
  };

  // State of the product.
  enum State {
    // The Status of the product is unknown.
    STATE_UNSPECIFIED = 0;

    // Product is under provisioning stage.
    STATE_PROVISIONING = 1;

    // Product is ok to run on instances.
    STATE_RUNNING = 2;

    // The product is about to terminate or has been announced for termination.
    STATE_TERMINATING = 3;

    // The product has been terminated.
    STATE_TERMINATED = 4;
  }

  // Identifier. Full name of the product resource.
  // ex "projects/1/locations/us-central1/products/office-2021"
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. Version of the product.
  string version = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. Company that released the product.
  string product_company = 3 [(google.api.field_behavior) = REQUIRED];

  // Output only. State of the product.
  State state = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. SKU for mapping to the Billing/Subscription resource.
  string sku = 5 [(google.api.field_behavior) = REQUIRED];

  // Required. Human-readable, detailed description of the Product
  string description = 6 [(google.api.field_behavior) = REQUIRED];

  // Required. Human-readable name of the Product
  string display_name = 7 [(google.api.field_behavior) = REQUIRED];
}

// Message describing Instance object
message Instance {
  option (google.api.resource) = {
    type: "licensemanager.googleapis.com/Instance"
    pattern: "projects/{project}/locations/{location}/instances/{instance}"
    plural: "instances"
    singular: "instance"
  };

  // VM status enum.
  enum State {
    // The Status of the VM is unspecified.
    STATE_UNSPECIFIED = 0;

    // Resources are being allocated for the instance.
    PROVISIONING = 1;

    // All required resources have been allocated and
    // the instance is being started.
    STAGING = 2;

    // The instance is running.
    RUNNING = 3;

    // The instance is currently stopping (either being deleted or terminated).
    STOPPING = 4;

    // The instance has stopped due to various reasons (user request, VM
    // preemption, project freezing, etc.).
    STOPPED = 5;

    // The instance has failed in some way.
    TERMINATED = 6;

    // The instance is in repair.
    REPAIRING = 7;
  }

  // Identifier. name of resource
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. [Output only] Create time stamp
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. [Output only] Update time stamp
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. Labels as key value pairs
  map<string, string> labels = 4 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The state of the VM.
  State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The location of the VM.
  string region = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Map with Product_Name and Activation State of the VM.
  map<string, ActivationState> product_activation = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. license version id.
  string license_version_id = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. Compute Instance resource name, i.e.
  // projects/{project}/zones/{zone}/instances/{instance}
  string compute_instance = 9 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "compute.googleapis.com/ComputeInstance"
    }
  ];
}

// Message describing total counts of users who accessed a VM.
message Usage {
  // LiMa Instance resource name, i.e.
  // projects/{project}/locations/{location}/instances/{instance}
  string lima_instance = 1 [(google.api.resource_reference) = {
    type: "licensemanager.googleapis.com/Instance"
  }];

  // Number of unique users accessing the VM.
  int32 users = 2;
}
