|
|
@@ -1,11 +1,115 @@
|
|
|
#ifndef SANDBOX_CLIENT_HPP_
|
|
|
#define SANDBOX_CLIENT_HPP_
|
|
|
|
|
|
+#include <cstdint>
|
|
|
+#include <fmt/core.h>
|
|
|
+#include <fmt/format.h>
|
|
|
+#include <map>
|
|
|
+#include <string>
|
|
|
+#include <vector>
|
|
|
+
|
|
|
+#include <nlohmann/json.hpp>
|
|
|
+
|
|
|
namespace sandbox {
|
|
|
-class Client {
|
|
|
-private:
|
|
|
-public:
|
|
|
+
|
|
|
+struct Money {
|
|
|
+ int64_t amount;
|
|
|
+ std::string currency;
|
|
|
+
|
|
|
+ Money() = default;
|
|
|
+ Money(int64_t amount, std::string currency)
|
|
|
+ : amount(amount), currency(std::move(currency)) {}
|
|
|
+
|
|
|
+ static Money from_double(double value, std::string currency) {
|
|
|
+ return Money(static_cast<int64_t>(value * 100 + 0.5), std::move(currency));
|
|
|
+ }
|
|
|
+
|
|
|
+ double to_double() const { return static_cast<double>(amount) / 100.0; }
|
|
|
+};
|
|
|
+
|
|
|
+inline void to_json(nlohmann::json &j, const Money &money) {
|
|
|
+ j = nlohmann::json{{"amount", money.amount}, {"currency", money.currency}};
|
|
|
+}
|
|
|
+
|
|
|
+inline void from_json(const nlohmann::json &j, Money &money) {
|
|
|
+ j.at("amount").get_to(money.amount);
|
|
|
+ j.at("currency").get_to(money.currency);
|
|
|
+}
|
|
|
+
|
|
|
+struct ClientInfo {
|
|
|
+ std::string id;
|
|
|
+ std::string old_id;
|
|
|
+ bool contractor = false;
|
|
|
+ std::string full_name;
|
|
|
+ std::string type;
|
|
|
+ std::string email;
|
|
|
+ std::string legal_address;
|
|
|
+ std::string physical_address;
|
|
|
+ std::string note;
|
|
|
+
|
|
|
+ Money income;
|
|
|
+
|
|
|
+ std::vector<std::string> tags;
|
|
|
+ std::vector<std::string> phones;
|
|
|
+ std::map<std::string, std::string> metadata;
|
|
|
+
|
|
|
+ ClientInfo() = default;
|
|
|
+
|
|
|
+ static void to_json(nlohmann::json &j, const ClientInfo &client) {
|
|
|
+ j = nlohmann::json{
|
|
|
+ {"id", client.id},
|
|
|
+ {"contractor", client.contractor},
|
|
|
+ {"full_name", client.full_name},
|
|
|
+ {"type", client.type},
|
|
|
+ {"tags", client.tags},
|
|
|
+ {"phones", client.phones},
|
|
|
+ {"metadata", client.metadata},
|
|
|
+ {"old_id", client.old_id},
|
|
|
+ {"email", client.email},
|
|
|
+ {"legal_address", client.legal_address},
|
|
|
+ {"physical_address", client.physical_address},
|
|
|
+ {"note", client.note},
|
|
|
+ {"income", client.income},
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ static void from_json(const nlohmann::json &j, ClientInfo &client) {
|
|
|
+ j.at("id").get_to(client.id);
|
|
|
+ j.at("full_name").get_to(client.full_name);
|
|
|
+ j.at("type").get_to(client.type);
|
|
|
+ j.at("old_id").get_to(client.old_id);
|
|
|
+ j.at("email").get_to(client.email);
|
|
|
+ j.at("legal_address").get_to(client.legal_address);
|
|
|
+ j.at("physical_address").get_to(client.physical_address);
|
|
|
+ j.at("note").get_to(client.note);
|
|
|
+ j.at("contractor").get_to(client.contractor);
|
|
|
+ j.at("income").get_to(client.income);
|
|
|
+ j.at("tags").get_to(client.tags);
|
|
|
+ j.at("phones").get_to(client.phones);
|
|
|
+ j.at("metadata").get_to(client.metadata);
|
|
|
+ }
|
|
|
+
|
|
|
+ static ClientInfo from_json(const nlohmann::json &j) {
|
|
|
+ ClientInfo client;
|
|
|
+ ClientInfo::from_json(j, client);
|
|
|
+ return client;
|
|
|
+ }
|
|
|
+
|
|
|
+ nlohmann::json to_json() const {
|
|
|
+ nlohmann::json j;
|
|
|
+ ClientInfo::to_json(j, *this);
|
|
|
+ return j;
|
|
|
+ }
|
|
|
};
|
|
|
+
|
|
|
+inline void to_json(nlohmann::json &j, const ClientInfo &client) {
|
|
|
+ ClientInfo::to_json(j, client);
|
|
|
+}
|
|
|
+
|
|
|
+inline void from_json(const nlohmann::json &j, ClientInfo &client) {
|
|
|
+ ClientInfo::from_json(j, client);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace sandbox
|
|
|
|
|
|
#endif
|