use crate::db::{SledModel, Storable}; // Import Sled 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, pub created_at: DateTime, pub updated_at: DateTime, } // 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(); } } // Implement Storable trait (provides default dump/load) impl Storable for Shareholder {} // Implement SledModel trait impl SledModel for Shareholder { fn get_id(&self) -> String { self.id.to_string() } fn db_prefix() -> &'static str { "shareholder" } }