67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
#include "modern/ui/catalog.hpp"
|
|
#include <optional>
|
|
|
|
namespace bmh::modern_ui {
|
|
enum class NewsLanguage { de, en };
|
|
enum class NewsScopeKind { club, national, global };
|
|
struct NewsEntity {
|
|
std::string id, name;
|
|
std::optional<std::pair<std::string, std::string>> localized_names;
|
|
Json json() const;
|
|
};
|
|
struct NewsScope {
|
|
NewsScopeKind kind = NewsScopeKind::club;
|
|
NewsEntity team;
|
|
Json json() const;
|
|
};
|
|
// Always two decimal places, unlike the general DTO's explicit minorUnits.
|
|
// No implicit conversion from DTO/native integer amounts is provided.
|
|
struct NewsMinorMoney {
|
|
int64_t minor = 0;
|
|
std::string currency;
|
|
Json json() const;
|
|
};
|
|
std::optional<NewsMinorMoney> news_money_from_dto(const Json &,
|
|
std::string &error);
|
|
struct NewsEvent {
|
|
std::string id, type, date;
|
|
NewsScope scope;
|
|
Json data =
|
|
Json::object(); // Every field is validated against registry types.
|
|
std::optional<std::string> variant;
|
|
bool demo = false;
|
|
Json json() const;
|
|
};
|
|
struct NewsRenderContext {
|
|
NewsLanguage language = NewsLanguage::de;
|
|
std::optional<NewsEntity> manager;
|
|
std::optional<std::string> as_of;
|
|
Json json() const;
|
|
};
|
|
// Pure authored-text renderer. Names come from the normalized world/adapter;
|
|
// UTF-8 is checked and preserved. This module adds no Unicode runtime library.
|
|
class NewsCatalog {
|
|
public:
|
|
explicit NewsCatalog(Json catalogue);
|
|
static NewsCatalog load(const fs::path &);
|
|
Json registry() const;
|
|
const Json &data() const { return catalogue_; }
|
|
Json from_event(const NewsEvent &, const NewsRenderContext & = {}) const;
|
|
Json from_event(const Json &, const Json &context = Json::object()) const;
|
|
Json validate_article(const Json &) const;
|
|
Json example(const std::string &template_id,
|
|
const Json &options = Json::object()) const;
|
|
Json from_almanac(const Json &, const Json &) const;
|
|
|
|
private:
|
|
Json catalogue_;
|
|
};
|
|
// Stable canonical facts/dedupe identity, matching the HTML event contract.
|
|
std::string news_canonical(const Json &);
|
|
std::string news_hash(const std::string &);
|
|
bool news_iso_date(const std::string &);
|
|
bool news_scope_matches(const Json &article_scope, const Json ¤t_scope);
|
|
} // namespace bmh::modern_ui
|