db/heromodels/src/models/finance/account.rs
2025-06-19 13:18:10 +03:00

93 lines
2.7 KiB
Rust

// heromodels/src/models/finance/account.rs
use heromodels_core::BaseModelData;
use heromodels_derive::model;
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};
use super::asset::Asset;
/// Account represents a financial account owned by a user
#[derive(Debug, Clone, Serialize, Deserialize, CustomType, Default)]
#[model] // Has base.Base in V spec
pub struct Account {
pub base_data: BaseModelData,
pub name: String, // internal name of the account for the user
pub user_id: u32, // user id of the owner of the account
pub description: String, // optional description of the account
pub ledger: String, // describes the ledger/blockchain where the account is located
pub address: String, // address of the account on the blockchain
pub pubkey: String, // public key
pub assets: Vec<u32>, // list of assets in this account
}
impl Account {
/// Create a new account with default values
pub fn new() -> Self {
Self {
base_data: BaseModelData::new(),
name: String::new(),
user_id: 0,
description: String::new(),
ledger: String::new(),
address: String::new(),
pubkey: String::new(),
assets: Vec::new(),
}
}
/// Set the name of the account
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
/// Set the user ID of the account owner
pub fn user_id(mut self, user_id: u32) -> Self {
self.user_id = user_id;
self
}
/// Set the description of the account
pub fn description(mut self, description: impl ToString) -> Self {
self.description = description.to_string();
self
}
/// Set the ledger/blockchain where the account is located
pub fn ledger(mut self, ledger: impl ToString) -> Self {
self.ledger = ledger.to_string();
self
}
/// Set the address of the account on the blockchain
pub fn address(mut self, address: impl ToString) -> Self {
self.address = address.to_string();
self
}
/// Set the public key of the account
pub fn pubkey(mut self, pubkey: impl ToString) -> Self {
self.pubkey = pubkey.to_string();
self
}
/// Add an asset to the account
pub fn add_asset(mut self, asset_id: u32) -> Self {
self.assets.push(asset_id);
self
}
/// Get the total value of all assets in the account
pub fn total_value(&self) -> f64 {
// TODO: implement
0.0
}
/// Find an asset by name
pub fn find_asset_by_name(&self, _name: &str) -> Option<&Asset> {
// TODO: implement
return None;
}
}