db/herodb_old/src/models/gov/shareholder.rs
2025-04-22 12:53:17 +04:00

78 lines
1.9 KiB
Rust

use crate::db::{Model, Storable}; // Import db traits
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
// use std::collections::HashMap; // Removed unused import
// use super::db::Model; // Removed old Model trait import
/// ShareholderType represents the type of shareholder
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShareholderType {
Individual,
Corporate,
}
/// Shareholder represents a shareholder of a company
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] // Added PartialEq
pub struct Shareholder {
pub id: u32,
pub company_id: u32,
pub user_id: u32,
pub name: String,
pub shares: f64,
pub percentage: f64,
pub type_: ShareholderType,
pub since: DateTime<Utc>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
// Removed old Model trait implementation
impl Shareholder {
/// Create a new shareholder with default timestamps
pub fn new(
id: u32,
company_id: u32,
user_id: u32,
name: String,
shares: f64,
percentage: f64,
type_: ShareholderType,
) -> Self {
let now = Utc::now();
Self {
id,
company_id,
user_id,
name,
shares,
percentage,
type_,
since: now,
created_at: now,
updated_at: now,
}
}
/// Update the shares owned by this shareholder
pub fn update_shares(&mut self, shares: f64, percentage: f64) {
self.shares = shares;
self.percentage = percentage;
self.updated_at = Utc::now();
}
}
impl Storable for Shareholder{}
// Implement Model trait
impl Model for Shareholder {
fn get_id(&self) -> u32 {
self.id
}
fn db_prefix() -> &'static str {
"shareholder"
}
}