diff options
Diffstat (limited to 'include/cepis/models.hpp')
| -rw-r--r-- | include/cepis/models.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/cepis/models.hpp b/include/cepis/models.hpp index faa2dde..6252001 100644 --- a/include/cepis/models.hpp +++ b/include/cepis/models.hpp @@ -96,6 +96,45 @@ struct Address { static Address from_json(const Json& data); }; +/// The municipality a CEP that does **not** exist would have belonged to. +/// +/// It arrives on a `404`, attached to `CepNotFound`. It is context for an +/// error, never an address: the CEP still does not exist, and nothing in this +/// block makes it deliverable. Treat it as a hint for the message you show — +/// "did you mean somewhere in Areal/RJ?" — not as a result. +/// +/// It exists because a CEP that fails is rarely random. It is usually someone +/// who knows the city and guessed the number, and the classic guess is the +/// `-000` that 957 municipalities never received. +/// +/// `cep_ini` and `cep_fim` are the smallest and the largest CEP that +/// **actually exist** in that municipality — not the bounds the Correios +/// publish. For Areal the DNE's own start is `25845000`, which is precisely +/// the CEP that just failed; `cep_ini` is `25845001`. +/// +/// The range is also **sparse**: Areal's 118 CEPs are scattered across the +/// ~4,900 numbers between `25845001` and `25849899`. That is what `ceps` is +/// for. The pair is a span, not a list — walking from `cep_ini` to `cep_fim` +/// produces thousands of CEPs that do not exist either. +struct Faixa { + std::string localidade; + std::string uf; + std::string estado; + std::string regiao; + std::string ibge; + std::string cep_ini; + std::string cep_fim; + std::int64_t ceps = 0; + + /// Reads the API's `faixa` block, or `std::nullopt` when it cannot be read. + /// + /// Anything unexpected — a missing block, a non-object, an empty one, a + /// municipality without a name — yields `std::nullopt` rather than an + /// error. The 404 is already the answer; failing to read the hint attached + /// to it must not turn a clean not-found into a parse failure. + static std::optional<Faixa> from_json(const Json& data); +}; + /// The response of `GET /health`. /// /// Good for two things: checking that the API answers, and knowing **which |