db/heromodels/src/models/biz/shareholder.rs
2025-06-12 05:22:17 +03:00

81 lines
2.0 KiB
Rust

use serde::{Deserialize, Serialize};
use heromodels_core::BaseModelData;
use heromodels_derive::model;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ShareholderType {
Individual,
Corporate,
}
impl Default for ShareholderType {
fn default() -> Self {
ShareholderType::Individual
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[model]
pub struct Shareholder {
pub base_data: BaseModelData,
pub company_id: u32,
pub user_id: u32, // Or other entity ID
pub name: String,
pub shares: f64,
pub percentage: f64,
pub type_: ShareholderType,
pub since: i64, // Timestamp
}
impl Shareholder {
pub fn new() -> Self {
Self {
base_data: BaseModelData::new(),
company_id: 0, // Default, to be set by builder
user_id: 0, // Default, to be set by builder
name: String::new(), // Default
shares: 0.0, // Default
percentage: 0.0, // Default
type_: ShareholderType::default(), // Uses ShareholderType's Default impl
since: 0, // Default timestamp, to be set by builder
}
}
// Builder methods
pub fn company_id(mut self, company_id: u32) -> Self {
self.company_id = company_id;
self
}
pub fn user_id(mut self, user_id: u32) -> Self {
self.user_id = user_id;
self
}
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
pub fn shares(mut self, shares: f64) -> Self {
self.shares = shares;
self
}
pub fn percentage(mut self, percentage: f64) -> Self {
self.percentage = percentage;
self
}
pub fn type_(mut self, type_: ShareholderType) -> Self {
self.type_ = type_;
self
}
pub fn since(mut self, since: i64) -> Self {
self.since = since;
self
}
// Base data operations are now handled by BaseModelDataOps trait
}