Skip to main content

gingr/mapping/
pet.rs

1use crate::{endpoint, response};
2use domain::pet;
3
4use super::{Error, ProviderField, Result};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7/// Pet mapping candidate produced from Gingr animal name fields.
8pub struct NameCandidate {
9    /// Gingr animal identifier kept as source evidence for the mapped pet.
10    pub provider_animal_id: endpoint::AnimalId,
11    /// Provider display label retained for operator context; NVA-specific naming rules are applied downstream.
12    pub name: pet::Name,
13}
14
15/// Extracts the pet name Gingr exposed for animal-to-domain mapping.
16pub fn name_candidate(record: &response::AnimalRecord) -> Result<NameCandidate> {
17    let name = record
18        .name
19        .as_deref()
20        .ok_or(Error::MissingRequiredProviderField {
21            field: ProviderField::AnimalName,
22        })?;
23    let name = pet::Name::try_new(name).map_err(|err| Error::InvalidDomainValue {
24        field: ProviderField::AnimalName,
25        reason: err.to_string(),
26    })?;
27
28    Ok(NameCandidate {
29        provider_animal_id: record.id,
30        name,
31    })
32}