use std::collections::HashSet;
use crate::datasets::sec::error::Result;
use super::sinks::{write_identity_row, Sinks};
pub mod companies;
#[derive(Default)]
pub struct Identities {
seen_companies: HashSet<String>,
seen_people: HashSet<String>,
seen_securities: HashSet<String>,
seen_managers: HashSet<String>,
}
impl Identities {
pub fn new() -> Self {
Self::default()
}
pub fn mark_company_seen(&mut self, cik: &str) {
self.seen_companies.insert(cik.to_string());
}
#[allow(clippy::too_many_arguments)]
pub fn ensure_company(
&mut self,
sinks: &mut Sinks,
cik: &str,
name: &str,
sic: &str,
sic_description: &str,
state_of_incorporation: &str,
fiscal_year_end: &str,
tickers: &str,
exchanges: &str,
entity_type: &str,
former_names: &str,
) -> Result<()> {
if self.seen_companies.insert(cik.to_string()) {
write_identity_row(
&mut sinks.company,
&[
cik,
name,
sic,
sic_description,
state_of_incorporation,
fiscal_year_end,
tickers,
exchanges,
entity_type,
former_names,
],
)?;
}
Ok(())
}
pub fn ensure_person(
&mut self,
sinks: &mut Sinks,
person_nid: &str,
display_name: &str,
cik: &str,
) -> Result<()> {
if self.seen_people.insert(person_nid.to_string()) {
write_identity_row(&mut sinks.person, &[person_nid, display_name, cik])?;
}
Ok(())
}
pub fn ensure_security(
&mut self,
sinks: &mut Sinks,
cusip: &str,
name: &str,
title_of_class: &str,
) -> Result<()> {
if self.seen_securities.insert(cusip.to_string()) {
write_identity_row(&mut sinks.security, &[cusip, name, title_of_class])?;
}
Ok(())
}
pub fn ensure_manager(
&mut self,
sinks: &mut Sinks,
manager_cik: &str,
name: &str,
) -> Result<()> {
if self.seen_managers.insert(manager_cik.to_string()) {
write_identity_row(&mut sinks.manager, &[manager_cik, name])?;
}
Ok(())
}
pub fn counts(&self) -> IdentityCounts {
IdentityCounts {
companies: self.seen_companies.len(),
people: self.seen_people.len(),
securities: self.seen_securities.len(),
managers: self.seen_managers.len(),
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct IdentityCounts {
pub companies: usize,
pub people: usize,
pub securities: usize,
pub managers: usize,
}