use serde::Deserialize;
use serde::Serialize;

use crate::common::inscriptions::Location;
use crate::common::inscriptions::Outpoint;

use super::electrs::BlockInfo;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct InscriptionHistory {
    pub index: u32,
    pub genesis: Outpoint,
    pub number: u64,
    pub from: String,
    pub to: String,
    pub from_location: Location,
    pub to_location: Location,
    pub from_value: u64,
    pub to_value: u64,
    pub is_creation: bool,
    pub leaked: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct InscriptionsHistory {
    pub data: Vec<(BlockInfo, Vec<InscriptionHistory>)>,
    pub reorg: Vec<u32>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct InscriptionHistoryBlock {
    pub info: BlockInfo,
    pub inscriptions: Vec<InscriptionHistory>,
}

impl From<InscriptionsHistory> for Vec<InscriptionHistoryBlock> {
    fn from(v: InscriptionsHistory) -> Self {
        v.data.into_iter().map(|v| InscriptionHistoryBlock { info: v.0, inscriptions: v.1 }).collect()
    }
}
