// file: kb_lib/src/db/entities/dex_event_coverage_entry.rs

//! Database entities for DEX event coverage rows.

/// Persisted coverage row for one listed upstream/local event entry.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, sqlx::FromRow)]
pub struct DexEventCoverageEntryEntity {
    /// Internal row id.
    pub id: i64,
    /// Stable unique key used for idempotent upserts.
    pub coverage_key: std::string::String,
    /// Internal decoder code.
    pub decoder_code: std::string::String,
    /// Optional Solana program id associated with the source entry.
    pub program_id: std::option::Option<std::string::String>,
    /// Program family.
    pub program_family: std::string::String,
    /// Surface kind such as AMM, CLMM, launch, orderbook or aggregator.
    pub surface_kind: std::string::String,
    /// Source repository or registry source.
    pub source_repo: std::option::Option<std::string::String>,
    /// Source path inside the repository or registry source.
    pub source_path: std::option::Option<std::string::String>,
    /// Entry kind such as instruction, event, account, log or program_data.
    pub entry_kind: std::string::String,
    /// Source entry name.
    pub entry_name: std::string::String,
    /// Optional discriminator encoded as lowercase hexadecimal.
    pub discriminator_hex: std::option::Option<std::string::String>,
    /// Optional discriminator byte length.
    pub discriminator_len: std::option::Option<i64>,
    /// Normalized event family.
    pub event_family: std::option::Option<std::string::String>,
    /// Expected DB target table or audit-only target.
    pub expected_db_target: std::option::Option<std::string::String>,
    /// Proof status for this entry.
    pub proof_status: std::string::String,
    /// Local event kind produced by the decoder, when any.
    pub local_event_kind: std::option::Option<std::string::String>,
    /// Number of observed decoded/audit rows in the local corpus.
    pub observed_count: i64,
    /// Number of rows materialized into specialized business tables.
    pub materialized_count: i64,
    /// Number of trade rows produced from this entry.
    pub trade_count: i64,
    /// First local signature observed for this entry.
    pub first_signature: std::option::Option<std::string::String>,
    /// Last local signature observed for this entry.
    pub last_signature: std::option::Option<std::string::String>,
    /// Notes preserving uncertainty, mapping decisions or DB gaps.
    pub notes: std::option::Option<std::string::String>,
    /// Creation timestamp.
    pub created_at: std::string::String,
    /// Update timestamp.
    pub updated_at: std::string::String,
}

/// Aggregated event coverage row grouped by decoder.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, sqlx::FromRow)]
pub struct DexEventCoverageSummaryEntity {
    /// Internal decoder code.
    pub decoder_code: std::string::String,
    /// Number of listed coverage entries.
    pub listed_entry_count: i64,
    /// Number of entries wired to a local event kind.
    pub decoded_entry_count: i64,
    /// Number of entries observed at least once in local corpus counts.
    pub observed_entry_count: i64,
    /// Number of entries materialized at least once.
    pub materialized_entry_count: i64,
    /// Sum of local observed counts.
    pub total_observed_count: i64,
    /// Sum of local materialized counts.
    pub total_materialized_count: i64,
    /// Sum of trade counts produced by these entries.
    pub trade_count: i64,
    /// Number of decoded entries that remain audit-only.
    pub audit_only_entry_count: i64,
    /// Number of entries without an expected DB target.
    pub missing_db_target_entry_count: i64,
    /// Number of entries still upstream Git unverified.
    pub upstream_git_unverified_entry_count: i64,
    /// Number of entries mapped but not locally observed.
    pub upstream_git_mapped_unverified_entry_count: i64,
    /// Number of entries observed in local corpus.
    pub upstream_git_local_corpus_observed_entry_count: i64,
    /// Number of entries materialized from local corpus.
    pub upstream_git_local_corpus_materialized_entry_count: i64,
}
