/*
 * Rosetta
 *
 * Build Once. Integrate Your Blockchain Everywhere.
 *
 * The version of the OpenAPI document: 1.4.13
 *
 * Generated by: https://openapi-generator.tech
 */

/// Operation : Operations contain all balance-changing information within a transaction. They are always one-sided (only affect 1 AccountIdentifier) and can succeed or fail independently from a Transaction.  Operations are used both to represent on-chain data (Data API) and to construct new transactions (Construction API), creating a standard interface for reading and writing to blockchains.

#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Operation {
    #[serde(rename = "operation_identifier")]
    pub operation_identifier: crate::OperationIdentifier,
    /// Restrict referenced related_operations to identifier indices < the current operation_identifier.index. This ensures there exists a clear DAG-structure of relations.  Since operations are one-sided, one could imagine relating operations in a single transfer or linking operations in a call tree.
    #[serde(rename = "related_operations", skip_serializing_if = "Option::is_none")]
    pub related_operations: Option<Vec<crate::OperationIdentifier>>,
    /// Type is the network-specific type of the operation. Ensure that any type that can be returned here is also specified in the NetworkOptionsResponse. This can be very useful to downstream consumers that parse all block data.
    #[serde(rename = "type")]
    pub r#type: String,
    /// Status is the network-specific status of the operation. Status is not defined on the transaction object because blockchains with smart contracts may have transactions that partially apply (some operations are successful and some are not). Blockchains with atomic transactions (all operations succeed or all operations fail) will have the same status for each operation.  On-chain operations (operations retrieved in the `/block` and `/block/transaction` endpoints) MUST have a populated status field (anything on-chain must have succeeded or failed). However, operations provided during transaction construction (often times called \"intent\" in the documentation) MUST NOT have a populated status field (operations yet to be included on-chain have not yet succeeded or failed).
    #[serde(rename = "status", skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[serde(rename = "account", skip_serializing_if = "Option::is_none")]
    pub account: Option<crate::AccountIdentifier>,
    #[serde(rename = "amount", skip_serializing_if = "Option::is_none")]
    pub amount: Option<crate::Amount>,
    #[serde(rename = "coin_change", skip_serializing_if = "Option::is_none")]
    pub coin_change: Option<crate::CoinChange>,
    #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")]
    pub metadata: Option<serde_json::Value>,
}

impl Operation {
    /// Operations contain all balance-changing information within a transaction. They are always one-sided (only affect 1 AccountIdentifier) and can succeed or fail independently from a Transaction.  Operations are used both to represent on-chain data (Data API) and to construct new transactions (Construction API), creating a standard interface for reading and writing to blockchains.
    pub fn new(operation_identifier: crate::OperationIdentifier, r#type: String) -> Operation {
        Operation {
            operation_identifier,
            related_operations: None,
            r#type,
            status: None,
            account: None,
            amount: None,
            coin_change: None,
            metadata: None,
        }
    }
}
