use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SemanticType {
FirstName,
LastName,
FullName,
Username,
DisplayName,
Email,
Phone,
PhoneCountryCode,
StreetAddress,
City,
State,
ZipCode,
PostalCode,
Country,
CountryCode,
Latitude,
Longitude,
CompanyName,
JobTitle,
Department,
Industry,
Url,
DomainName,
IpAddress,
MacAddress,
UserAgent,
Slug,
Title,
Description,
Bio,
Paragraph,
Sentence,
HtmlContent,
MarkdownContent,
ImageUrl,
AvatarUrl,
ThumbnailUrl,
FileUrl,
FileName,
MimeType,
FileSize,
Price,
Currency,
CurrencyCode,
Amount,
Percentage,
CreatedAt,
UpdatedAt,
DeletedAt,
StartDate,
EndDate,
BirthDate,
DateOnly,
TimeOnly,
Timestamp,
PasswordHash,
Token,
ApiKey,
SecretKey,
Uuid,
AutoIncrement,
ExternalId,
Sku,
OrderNumber,
InvoiceNumber,
TrackingNumber,
Status,
Role,
Priority,
Category,
Tag,
BooleanFlag,
EnumValue,
Quantity,
Rating,
Score,
Weight,
Height,
Age,
Duration,
SortOrder,
JsonData,
Color,
HexColor,
Locale,
Timezone,
Unknown,
}
impl SemanticType {
pub fn is_auto_generated(&self) -> bool {
matches!(self, SemanticType::AutoIncrement)
}
pub fn is_pii(&self) -> bool {
matches!(
self,
SemanticType::FirstName
| SemanticType::LastName
| SemanticType::FullName
| SemanticType::Email
| SemanticType::Phone
| SemanticType::StreetAddress
| SemanticType::BirthDate
| SemanticType::PasswordHash
| SemanticType::Token
| SemanticType::ApiKey
| SemanticType::SecretKey
| SemanticType::IpAddress
)
}
pub fn correlation_group(&self) -> Option<CorrelationGroup> {
match self {
SemanticType::StreetAddress
| SemanticType::City
| SemanticType::State
| SemanticType::ZipCode
| SemanticType::PostalCode
| SemanticType::Country
| SemanticType::CountryCode => Some(CorrelationGroup::Address),
SemanticType::Latitude | SemanticType::Longitude => {
Some(CorrelationGroup::GeoCoordinates)
}
SemanticType::FirstName
| SemanticType::LastName
| SemanticType::FullName
| SemanticType::Email
| SemanticType::Username => Some(CorrelationGroup::PersonIdentity),
SemanticType::CreatedAt | SemanticType::UpdatedAt | SemanticType::DeletedAt => {
Some(CorrelationGroup::Temporal)
}
SemanticType::StartDate | SemanticType::EndDate => {
Some(CorrelationGroup::TemporalRange)
}
_ => None,
}
}
}
impl fmt::Display for SemanticType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum CorrelationGroup {
Address,
GeoCoordinates,
PersonIdentity,
Temporal,
TemporalRange,
}
impl fmt::Display for CorrelationGroup {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CorrelationGroup::Address => write!(f, "Address"),
CorrelationGroup::GeoCoordinates => write!(f, "GeoCoordinates"),
CorrelationGroup::PersonIdentity => write!(f, "PersonIdentity"),
CorrelationGroup::Temporal => write!(f, "Temporal"),
CorrelationGroup::TemporalRange => write!(f, "TemporalRange"),
}
}
}