use serde::{Deserialize, Serialize}; use heromodels_core::{BaseModelData, Model, IndexKey, IndexKeyBuilder, Index}; use rhai::{CustomType, TypeBuilder}; // For #[derive(CustomType)] use heromodels_core::BaseModelDataOps; use heromodels_derive::model; // --- Enums --- #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum CompanyStatus { Active, Inactive, Suspended, } impl Default for CompanyStatus { fn default() -> Self { CompanyStatus::Inactive } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum BusinessType { Coop, Single, Twin, Starter, Global, } impl Default for BusinessType { fn default() -> Self { BusinessType::Single } } // --- Company Struct --- #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, CustomType, Default)] // Added CustomType #[model] pub struct Company { pub base_data: BaseModelData, pub name: String, pub registration_number: String, pub incorporation_date: i64, // Changed to i64 // Timestamp pub fiscal_year_end: String, // e.g., "MM-DD" pub email: String, pub phone: String, pub website: String, pub address: String, pub business_type: BusinessType, pub industry: String, pub description: String, pub status: CompanyStatus, } // --- Index Implementations (Example) --- pub struct CompanyNameIndex; impl Index for CompanyNameIndex { type Model = Company; type Key = str; fn key() -> &'static str { "name" } } pub struct CompanyRegistrationNumberIndex; impl Index for CompanyRegistrationNumberIndex { type Model = Company; type Key = str; fn key() -> &'static str { "registration_number" } } // --- Builder Pattern --- impl BaseModelDataOps for Company { fn get_base_data_mut(&mut self) -> &mut BaseModelData { &mut self.base_data } } impl Company { pub fn new() -> Self { Self { base_data: BaseModelData::new(), name: String::new(), registration_number: String::new(), incorporation_date: 0, fiscal_year_end: String::new(), email: String::new(), phone: String::new(), website: String::new(), address: String::new(), business_type: BusinessType::default(), industry: String::new(), description: String::new(), status: CompanyStatus::default(), } } pub fn name(mut self, name: impl ToString) -> Self { self.name = name.to_string(); self } pub fn registration_number(mut self, registration_number: impl ToString) -> Self { self.registration_number = registration_number.to_string(); self } pub fn incorporation_date(mut self, incorporation_date: i64) -> Self { self.incorporation_date = incorporation_date; self } pub fn fiscal_year_end(mut self, fiscal_year_end: impl ToString) -> Self { self.fiscal_year_end = fiscal_year_end.to_string(); self } pub fn email(mut self, email: impl ToString) -> Self { self.email = email.to_string(); self } pub fn phone(mut self, phone: impl ToString) -> Self { self.phone = phone.to_string(); self } pub fn website(mut self, website: impl ToString) -> Self { self.website = website.to_string(); self } pub fn address(mut self, address: impl ToString) -> Self { self.address = address.to_string(); self } pub fn business_type(mut self, business_type: BusinessType) -> Self { self.business_type = business_type; self } pub fn industry(mut self, industry: impl ToString) -> Self { self.industry = industry.to_string(); self } pub fn description(mut self, description: impl ToString) -> Self { self.description = description.to_string(); self } pub fn status(mut self, status: CompanyStatus) -> Self { self.status = status; self } // Base data operations are now handled by BaseModelDataOps trait }