use std::collections::BTreeMap;

use crate::common::block::BlockNumber;
use crate::common::hash::Hash256;
use crate::common::inscriptions::{Address, InscriptionNumber, Location};
use crate::common::other::TimestampSec;
use crate::common::tokens::InscriptionProtocol;

#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
pub struct ElectrsInscription {
    pub tx_index: u32,
    pub location: Location,
    pub number: InscriptionNumber,
    pub content_type: Option<String>,
    pub owner: Address,
    pub value: u64,
    pub genesis_fee: u64,
    pub content: Option<Vec<u8>>,
    pub leaked: bool,
}

#[derive(Clone, Copy, PartialEq, PartialOrd, Ord, Eq, serde::Serialize, serde::Deserialize, Debug)]
pub struct ProtocolKey {
    pub tx_index: u32,
    pub inscription_number: InscriptionNumber,
}

/// Block data that electrs will push to dataswamp
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct ElectrsDataswampBlock {
    pub inscriptions: Vec<ElectrsInscription>,
    pub moves_history: Vec<InscriptionMove>,
    pub protocol: BTreeMap<ProtocolKey, InscriptionProtocol>,
    pub block_info: BlockInfo,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct InscriptionMove {
    pub tx_index: u32,
    pub leaked: bool,
    pub from: Address,
    pub to: Address,
    pub from_location: Location,
    pub to_location: Location,
    pub from_value: u64,
    pub to_value: u64,
    pub inscription_number: InscriptionNumber,
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
pub struct BlockInfo {
    pub height: BlockNumber,
    pub created_at: TimestampSec,
    pub block_hash: Hash256,
    pub prev_block_hash: Hash256,
}
