/**
 * # HCS Topic Information
 * The current network state of an Hedera Consensus Service (HCS) Topic.
 *
 * ### Keywords
 * The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
 * "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
 * document are to be interpreted as described in [RFC2119](https://www.ietf.org/rfc/rfc2119)
 * and clarified in [RFC8174](https://www.ietf.org/rfc/rfc8174).
 */
syntax = "proto3";

package proto;

// SPDX-License-Identifier: Apache-2.0
import "services_basic_types.proto";
import "services_custom_fees.proto";

option java_package = "com.hederahashgraph.api.proto.java";
// <<<pbj.java_package = "com.hedera.hapi.node.state.consensus">>> This comment is special code for setting PBJ Compiler java package
option java_multiple_files = true;

/**
 * Representation of an Hedera Consensus Service(HCS) topic.
 *
 * As with all network entities, a topic has a unique entity number, which is
 * usually given along with the network's shard and realm in the form of a
 * shard.realm.number id.<br/>
 * An HCS topic is an ordered logical stream of messages united and secured by
 * a running hash of those messages. The integrity of any message on a topic,
 * and the topic stream as a whole, can always be ascertained from block stream
 * data by recomputing the running hash across any subset of messages on the
 * topic.<br/>
 * The messages on a topic SHALL NOT be stored in network state, but are
 * available in the network block stream, and may be queried via the
 * Mirror Node system.
 */
message Topic {
    /**
     * The topic's ID.
     * <p>
     * This value SHALL be unique within the network.
     */
    TopicID topic_id = 1;

    /**
     * The number of messages sent to the topic.
     */
    int64 sequence_number = 2;

    /**
     * The expiration time for this topic, in seconds since the epoch.
     * <p>
     * For this purpose, `epoch` SHALL be the UNIX epoch with 0 at `1970-01-01T00:00:00.000Z`.
     */
    int64 expiration_second = 3;

    /**
     * The number of seconds for which the topic will be automatically renewed
     * upon expiring (if it has a valid auto-renew account).
     */
    int64 auto_renew_period = 4;

    /**
     * The id of the account (if any) that the network will attempt to charge
     * fees to complete auto-renewal of this topic, upon expiration.
     */
    AccountID auto_renew_account_id = 5;

    /**
     * A flag indicating that this topic is deleted.
     */
    bool deleted = 6;

    /**
     * The current running hash of this topic.
     * <p>
     * This 48-byte field is the output of a SHA-384 digest with input data
     * determined by the current version of the running hash algorithm used
     * by the network.<br/>
     * All topics in state SHALL use running hash algorithm version `3`.<br/>
     * The bytes of each uint64 or uint32 encoded for the hash input MUST be in
     * Big-Endian format.
     * <p>
     * <hr/>
     * If the algorithm version is '3', then the input data to the SHA-384
     * digest are, in order:
     * <ol>
     *   <li>The previous running hash of the topic (48 bytes)</li>
     *   <li>The `topicRunningHashVersion` (8 bytes)</li>
     *   <li>The payer account's shard (8 bytes)</li>
     *   <li>The payer account's realm (8 bytes)</li>
     *   <li>The payer account's number (8 bytes)</li>
     *   <li>The topic's shard (8 bytes)</li>
     *   <li>The topic's realm (8 bytes)</li>
     *   <li>The topic's number (8 bytes)</li>
     *   <li>The number of seconds since the epoch when the
     *       `ConsensusSubmitMessage` reached consensus (8 bytes)</li>
     *   <li>The number of nanoseconds within the second when the
     *       `ConsensusSubmitMessage` reached consensus (4 bytes)</li>
     *   <li>The `topicSequenceNumber` (8 bytes)</li>
     *   <li>The output of a SHA-384 digest of the message bytes from the
     *       `ConsensusSubmitMessage` (48 bytes)</li>
     * </ol>
     * <blockquote>Note that older messages on a topic, which are available in
     * the block stream, MAY use older algorithm versions, and the block stream
     * record incorporates a running hash version field to ensure the correct
     * hash calculation for each such historical message.</blockquote>
     */
    bytes running_hash = 7;

    /**
     * A short description of this topic.
     * <p>
     * This value, if set, MUST NOT exceed `transaction.maxMemoUtf8Bytes`
     * (default 100) bytes when encoded as UTF-8.
     */
    string memo = 8;

    /**
     * Access control for modification of the topic.
     * <p>
     * If this field is set, that key MUST sign each message to update or delete
     * this topic.<br/>
     * A topic without an admin key SHALL be immutable, except for expiration
     * and renewal.<br/>
     * If this field is not set, the `auto_renew_account_id` MUST NOT be set.
     */
    Key admin_key = 9;

    /**
     * Access control for message submission to the topic.
     * <p>
     * If this field is set, that key MUST sign each consensus submit message
     * for this topic.
     */
    Key submit_key = 10;

    /**
     * Access control for update/delete of custom fees.
     * <p>
     * If this field is unset, the current custom fees CANNOT be changed.<br/>
     * If this field is set, that `Key` MUST sign any transaction to update
     * the custom fee schedule for this topic.
     */
    Key fee_schedule_key = 11;

    /**
     * A set of "privileged payer" keys<br/>
     * Keys in this list are permitted to submit messages to this topic without
     * paying custom fees associated with this topic.
     * <p>
     * If a submit transaction is signed by _any_ key included in this set,
     * custom fees SHALL NOT be charged for that transaction.<br/>
     * A `fee_exempt_key_list` MUST NOT contain more than
     * `MAX_ENTRIES_FOR_FEE_EXEMPT_KEY_LIST` keys.<br/>
     * A `fee_exempt_key_list` MUST NOT contain any duplicate keys.<br/>
     * A `fee_exempt_key_list` MAY contain keys for accounts that are inactive,
     * deleted, or non-existent.
     * If not set, there SHALL NOT be any fee-exempt keys.  In particular, the
     * following keys SHALL NOT be implicitly or automatically added to this
     * list: `adminKey`, `submitKey`, `fee_schedule_key`.
     */
    repeated Key fee_exempt_key_list = 12;

    /**
     * A set of custom fee definitions.<br/>
     * These are fees to be assessed for each submit to this topic.
     * <p>
     * If this list is empty, the only fees charged for a submit to this
     * topic SHALL be the network and node fees.<br/>
     * If this list is not empty, each fee defined in this set SHALL
     * be evaluated for each message submitted to this topic, and the
     * resultant total assessed fees SHALL be charged.<br/>
     * If this list is not empty, custom fees defined here SHALL be
     * charged _in addition to_ the base network and node fees.
     */
    repeated FixedCustomFee custom_fees = 13;
}
