// Copyright 2026 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.universalledger.v1;

import "google/api/field_behavior.proto";
import "google/cloud/universalledger/v1/accounts.proto";
import "google/cloud/universalledger/v1/common.proto";
import "google/cloud/universalledger/v1/transactions.proto";

option csharp_namespace = "Google.Cloud.UniversalLedger.V1";
option go_package = "cloud.google.com/go/universalledger/apiv1/universalledgerpb;universalledgerpb";
option java_multiple_files = true;
option java_outer_classname = "QueryProto";
option java_package = "com.google.cloud.universalledger.v1";
option php_namespace = "Google\\Cloud\\UniversalLedger\\V1";
option ruby_package = "Google::Cloud::UniversalLedger::V1";

// Represents the state of an account on the ledger.
message Account {
  // Specific details based on the type of account.
  oneof account_details {
    // Output only. Details for a standard user account.
    UserDetails user_details = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for an account manager account.
    AccountManagerDetails account_manager_details = 4
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a token manager account.
    TokenManagerDetails token_manager_details = 5
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a contract token manager account.
    ContractTokenManagerDetails contract_token_manager_details = 12
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a smart contract account.
    ContractDetails contract_details = 11
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a clearinghouse account.
    ClearingHouseDetails clearinghouse_details = 10
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a currency operator account.
    CurrencyOperatorDetails currency_operator_details = 7
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Details for a platform operator account.
    PlatformOperatorDetails platform_operator_details = 8
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Output only. The sequence number of this account. This number increments
  // with each transaction sent by this account.
  int64 sequence_number = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The primary public key associated with this account, used for
  // signature verification.
  bytes public_key = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the execution round (similar to block "height") at
  // which the account information provided is accurate.
  int64 round_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The account comment stored when this account was created.
  string comment = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to an Account Manager.
message AccountManagerDetails {
  // Output only. Deprecated: Use `token_manager_id` instead.
  // The default token manager for accounts created by this account manager.
  Entity token_manager = 1
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The number of accounts created by this account manager.
  int32 num_accounts = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the default token manager for accounts created by
  // this account manager.
  string token_manager_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Token Manager.
message TokenManagerDetails {
  // Output only. The amount of tokens this token manager is allowed to mint.
  CurrencyValue issuance_limit = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The amount of tokens minted by this token manager.
  // This number will increase when minting and decrease when burning.
  CurrencyValue issued_tokens = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Contract Token Manager.
message ContractTokenManagerDetails {
  // Output only. The amount of tokens this contract token manager is allowed
  // to provide backing for.
  //
  // Since contract token managers cannot increase or decrease
  // their issuance limit, this should equal the `issued_tokens`.
  CurrencyValue issuance_limit = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The amount of tokens this contract token manager is
  // providing backing for (that is, its total liability).
  //
  // This equals to the sum of all balances held in contracts for its currency,
  // plus its net position in the settlement matrix.
  CurrencyValue issued_tokens = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The account ID of the previous contract token manager for this
  // currency. This forms an audit trail that can be traversed to discover all
  // previous managers. If this is the first contract token manager for the
  // currency, this will be empty.
  string previous_contract_token_manager_id = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The status of this account.
  AccountStatus account_status = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a User account.
message UserDetails {
  // Output only. Deprecated: Use `account_manager_id` instead.
  // The account manager for this user.
  Entity account_manager = 1
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the account manager for this user.
  string account_manager_id = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `token_manager_id` instead.
  // The token manager for this user.
  Entity token_manager = 2
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the token manager for this user.
  string token_manager_id = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The list of roles granted to this account.
  repeated Role roles = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The status of this account.
  AccountStatus account_status = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The token balance of this user account.
  CurrencyValue balance = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `contract_account_fields` instead.
  // The contract account fields (contract ID -> fields) for this user.
  map<string, Fields> account_fields = 6
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The contract account fields (contract ID -> fields) for this
  // user.
  map<string, Fields> contract_account_fields = 16
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Currency Operator.
message CurrencyOperatorDetails {
  // Output only. Deprecated: Use `currency_code` instead.
  // The currency associated with this account, represented by the 3-letter
  // ISO 4217 code.
  string currency = 1
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the currency associated with this account,
  // represented by the 3-letter ISO 4217 code.
  string currency_code = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The status of this account.
  AccountStatus account_status = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `previous_currency_operator_id` instead.
  // The previous currency operator which transferred ownership of the currency
  // operator role to this account. If this is the first currency operator for
  // the currency, this will be empty.
  Entity previous_entity_id = 3
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the previous currency operator which transferred
  // ownership of the currency operator role to this account. If this is the
  // first currency operator for the currency, this will be empty.
  string previous_currency_operator_id = 10
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `platform_operator_id` instead.
  // The platform operator which created this currency operator.
  Entity platform_operator_entity_id = 4
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the platform operator which created this currency
  // operator.
  string platform_operator_id = 11 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `contract_token_manager_id` instead.
  // The contract token manager associated with this currency operator.
  Entity contract_token_manager = 5
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the contract token manager associated with this
  // currency operator.
  string contract_token_manager_id = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the clearinghouse associated with this currency
  // operator.
  string clearinghouse_id = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Platform Operator.
message PlatformOperatorDetails {
  // Output only. The status of this account.
  AccountStatus account_status = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `previous_platform_operator_id` instead.
  // The previous platform operator which transferred ownership of the platform
  // operator role to this account. If this is the first platform operator, this
  // will be empty.
  Entity previous_entity_id = 2
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the previous platform operator which transferred
  // ownership of the platform operator role to this account. If this is the
  // first platform operator, this will be empty.
  string previous_platform_operator_id = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Clearinghouse.
message ClearingHouseDetails {
  // Output only. The status of this account.
  AccountStatus account_status = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The balances that this clearinghouse is currently tracking for
  // settlement.
  repeated BalanceToSettle balances = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The settlement mode of this clearinghouse.
  SettlementMode settlement_mode = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Details specific to a Smart Contract.
message ContractDetails {
  // Output only. Deprecated: Use `owner_id` instead.
  // The owner of the contract.
  Entity owner = 1
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the owner of the contract.
  string owner_id = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The serialized contract code.
  bytes code = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The contract fields (field name -> value) for this contract.
  Fields contract_fields = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The currency balances held by the contract (currency operator
  // -> balance).
  map<string, CurrencyValue> currency_balances = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// A balance to settle between two token managers.
message BalanceToSettle {
  // Output only. Deprecated: Use `balance_payer_id` instead.
  // The account which owes the balance to be settled.
  Entity balance_payer = 1
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the account which owes the balance to be settled.
  string balance_payer_id = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Deprecated: Use `balance_receiver_id` instead.
  // The account which is owed the balance to be settled.
  Entity balance_receiver = 2
      [deprecated = true, (google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The ID of the account which is owed the balance to be settled.
  string balance_receiver_id = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The balance to settle. Must be positive.
  CurrencyValue balance = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// A map of fields (field name -> value) from a contract used to represent
// contract fields or account fields.
message Fields {
  // Output only. The map of field names to their values.
  map<string, Value> fields = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}
