// file: kb_lib/src/db/dtos/program_instruction_discriminator_summary.rs

//! Program instruction discriminator summary DTO.

/// Aggregated instruction discriminator diagnostic row.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ProgramInstructionDiscriminatorSummaryDto {
    /// Program id.
    pub program_id: std::string::String,
    /// First eight decoded instruction-data bytes as hex.
    pub discriminator_hex: std::option::Option<std::string::String>,
    /// Known instruction name, when recognized by local diagnostic mapping.
    pub known_instruction_name: std::option::Option<std::string::String>,
    /// Number of accounts in the instruction.
    pub accounts_count: u64,
    /// Optional stack height.
    pub stack_height: std::option::Option<u32>,
    /// True when the grouped instructions are inner instructions.
    pub is_inner_instruction: bool,
    /// Number of instruction rows in this group.
    pub occurrence_count: u64,
    /// Number of distinct transactions in this group.
    pub transaction_count: u64,
    /// Number of instruction rows already linked to decoded events.
    pub decoded_event_count: u64,
    /// Number of instruction rows not linked to decoded events.
    pub undecoded_occurrence_count: u64,
    /// Latest observed slot.
    pub latest_slot: std::option::Option<u64>,
    /// Latest signature in this group.
    pub latest_signature: std::string::String,
    /// Latest instruction id in this group.
    pub latest_instruction_id: i64,
    /// Latest outer instruction index.
    pub latest_instruction_index: u32,
    /// Latest inner instruction index.
    pub latest_inner_instruction_index: std::option::Option<u32>,
    /// Latest parsed type.
    pub latest_parsed_type: std::option::Option<std::string::String>,
    /// Latest decoded event kind.
    pub latest_decoded_event_kind: std::option::Option<std::string::String>,
    /// Data JSON preview from the latest row.
    pub latest_data_json_preview: std::option::Option<std::string::String>,
    /// Accounts JSON preview from the latest row.
    pub latest_accounts_json_preview: std::option::Option<std::string::String>,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) struct ProgramInstructionDiscriminatorSummaryKey {
    pub(crate) program_id: std::string::String,
    pub(crate) discriminator_hex: std::option::Option<std::string::String>,
    pub(crate) accounts_count: u64,
    pub(crate) stack_height: std::option::Option<u32>,
    pub(crate) is_inner_instruction: bool,
}

#[derive(Debug, Clone)]
pub(crate) struct ProgramInstructionDiscriminatorSummaryAccumulator {
    pub(crate) key: ProgramInstructionDiscriminatorSummaryKey,
    pub(crate) known_instruction_name: std::option::Option<std::string::String>,
    pub(crate) occurrence_count: u64,
    pub(crate) decoded_event_count: u64,
    pub(crate) transaction_signatures: std::collections::BTreeSet<std::string::String>,
    pub(crate) latest_slot: std::option::Option<u64>,
    pub(crate) latest_signature: std::string::String,
    pub(crate) latest_instruction_id: i64,
    pub(crate) latest_instruction_index: u32,
    pub(crate) latest_inner_instruction_index: std::option::Option<u32>,
    pub(crate) latest_parsed_type: std::option::Option<std::string::String>,
    pub(crate) latest_decoded_event_kind: std::option::Option<std::string::String>,
    pub(crate) latest_data_json_preview: std::option::Option<std::string::String>,
    pub(crate) latest_accounts_json_preview: std::option::Option<std::string::String>,
}


