use ex3_canister_types::chain::Chain;
use serde::{Deserialize, Serialize};

use crate::{AssetAmount, AssetId};

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Withdrawal {
    pub chain: Chain,
    pub network: u8,
    pub address: String,
    pub asset: AssetId,
    pub amount: AssetAmount,
}

#[cfg(test)]
mod tests {
    use ex3_serde::bincode;

    use super::*;

    #[test]
    fn test_bincode_decode_encode() {
        let withdrawal = Withdrawal {
            chain: Chain::Ethereum,
            network: 1,
            address: "0x0000001312312321313213".to_string(),
            asset: AssetId::from(2000u32),
            amount: AssetAmount::from(10000u64),
        };

        let encoded = bincode::serialize(&withdrawal).unwrap();
        let decoded: Withdrawal = bincode::deserialize(&encoded).unwrap();
        assert_eq!(withdrawal, decoded);
    }
}
