crate::ix!();
#[derive(Getters,Debug,Serialize,Deserialize)]
#[getset(get="pub")]
pub struct IndexedAmazonTx {
quantity: i32,
index: String,
unit_price: MonetaryAmount,
order_date: NaiveDate,
product_name: String,
}
impl AmazonTxn for IndexedAmazonTx {}
pub type AmazonItemMap = HashMap<String,AmazonTx>;
pub fn create_amazon_item_map(config: &AmazonConfig) -> Option<AmazonItemMap> {
let contents = std::fs::read(&config.txfile()).unwrap();
let txns = parse_amazon_csv::<IndexedAmazonTx>(&contents).unwrap();
let mut x = HashMap::new();
for tx in txns.iter() {
let amazon_tx = AmazonTxBuilder::default()
.quantity(*tx.quantity())
.unit_price(*tx.unit_price())
.order_date(tx.order_date().clone())
.product_name(tx.product_name().clone())
.build()
.unwrap();
x.insert(tx.index.clone(), amazon_tx);
}
Some(x)
}