+void ConvPeriod(const std::string & value, std::optional<STG::Tariff::Period> & res)
+{
+std::string lowered = ToLower(value);
+if (lowered == "daily")
+ res = STG::Tariff::DAY;
+else if (lowered == "monthly")
+ res = STG::Tariff::MONTH;
+else
+ throw SGCONF::ACTION::ERROR("Period should be 'daily' or 'monthly'. Got: '" + value + "'");
+}
+
+void ConvChangePolicy(const std::string & value, std::optional<STG::Tariff::ChangePolicy> & res)
+{
+std::string lowered = ToLower(value);
+if (lowered == "allow")
+ res = STG::Tariff::ALLOW;
+else if (lowered == "to_cheap")
+ res = STG::Tariff::TO_CHEAP;
+else if (lowered == "to_expensive")
+ res = STG::Tariff::TO_EXPENSIVE;
+else if (lowered == "deny")
+ res = STG::Tariff::DENY;
+else
+ throw SGCONF::ACTION::ERROR("Change policy should be 'allow', 'to_cheap', 'to_expensive' or 'deny'. Got: '" + value + "'");
+}
+
+void ConvChangePolicyTimeout(const std::string & value, std::optional<time_t> & res)
+{
+struct tm brokenTime;
+if (stg_strptime(value.c_str(), "%Y-%m-%d %H:%M:%S", &brokenTime) == NULL)
+ throw SGCONF::ACTION::ERROR("Credit expiration should be in format 'YYYY-MM-DD HH:MM:SS'. Got: '" + value + "'");
+res = stg_timegm(&brokenTime);
+}
+
+void ConvTraffType(const std::string & value, std::optional<STG::Tariff::TraffType> & res)
+{
+std::string lowered = ToLower(value);
+lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end());
+if (lowered == "upload")
+ res = STG::Tariff::TRAFF_UP;
+else if (lowered == "download")
+ res = STG::Tariff::TRAFF_DOWN;
+else if (lowered == "upload+download")
+ res = STG::Tariff::TRAFF_UP_DOWN;
+else if (lowered.substr(0, 3) == "max")
+ res = STG::Tariff::TRAFF_MAX;
+else
+ throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'");
+}
+
+STG::DirPriceDataOpt ConvTimeSpan(const std::string & value)
+{
+size_t dashPos = value.find_first_of('-');
+if (dashPos == std::string::npos)
+ throw SGCONF::ACTION::ERROR("Time span should be in format 'hh:mm-hh:mm'. Got: '" + value + "'");
+size_t fromColon = value.find_first_of(':');
+if (fromColon == std::string::npos || fromColon > dashPos)
+ throw SGCONF::ACTION::ERROR("Time span should be in format 'hh:mm-hh:mm'. Got: '" + value + "'");
+size_t toColon = value.find_first_of(':', dashPos);
+if (toColon == std::string::npos)
+ throw SGCONF::ACTION::ERROR("Time span should be in format 'hh:mm-hh:mm'. Got: '" + value + "'");
+STG::DirPriceDataOpt res;
+res.hDay = FromString<int>(value.substr(0, fromColon));
+if (res.hDay.value() < 0 || res.hDay.value() > 23)
+ throw SGCONF::ACTION::ERROR("Invalid 'from' hours. Got: '" + value.substr(0, fromColon) + "'");
+res.mDay = FromString<int>(value.substr(fromColon + 1, dashPos - fromColon - 1));
+if (res.mDay.value() < 0 || res.mDay.value() > 59)
+ throw SGCONF::ACTION::ERROR("Invalid 'from' minutes. Got: '" + value.substr(fromColon + 1, dashPos - fromColon - 1) + "'");
+res.hNight = FromString<int>(value.substr(dashPos + 1, toColon - dashPos - 1));
+if (res.hNight.value() < 0 || res.hNight.value() > 23)
+ throw SGCONF::ACTION::ERROR("Invalid 'to' hours. Got: '" + value.substr(dashPos + 1, toColon - dashPos - 1) + "'");
+res.mNight = FromString<int>(value.substr(toColon + 1, value.length() - toColon));
+if (res.mNight.value() < 0 || res.mNight.value() > 59)
+ throw SGCONF::ACTION::ERROR("Invalid 'to' minutes. Got: '" + value.substr(toColon + 1, value.length() - toColon) + "'");
+return res;
+}
+
+void splice(std::vector<STG::DirPriceDataOpt> & lhs, const std::vector<STG::DirPriceDataOpt> & rhs)
+{
+for (size_t i = 0; i < lhs.size() && i < rhs.size(); ++i)
+ lhs[i].splice(rhs[i]);
+}
+
+void ConvTimes(std::string value, std::vector<STG::DirPriceDataOpt> & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvTimeSpan));
+}
+
+struct ConvPrice
+{
+ using MemPtr = std::optional<double> (STG::DirPriceDataOpt::*);
+ ConvPrice(MemPtr before, MemPtr after)
+ : m_before(before), m_after(after)
+ {}
+
+ STG::DirPriceDataOpt operator()(const std::string & value)
+ {
+ STG::DirPriceDataOpt res;
+ size_t slashPos = value.find_first_of('/');
+ if (slashPos == std::string::npos)
+ {
+ double price = 0;
+ if (str2x(value, price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value + "'");
+ (res.*m_before) = (res.*m_after) = price;
+ res.noDiscount = true;
+ }
+ else
+ {
+ double price = 0;
+ if (str2x(value.substr(0, slashPos), price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(0, slashPos) + "'");
+ (res.*m_before) = price;
+ if (str2x(value.substr(slashPos + 1, value.length() - slashPos), price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(slashPos + 1, value.length() - slashPos) + "'");
+ (res.*m_after) = price;
+ res.noDiscount = false;
+ }
+ return res;
+ }
+
+ MemPtr m_before;
+ MemPtr m_after;
+};
+
+void ConvDayPrices(std::string value, std::vector<STG::DirPriceDataOpt> & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvPrice(&STG::DirPriceDataOpt::priceDayA, &STG::DirPriceDataOpt::priceDayB)));
+}
+
+void ConvNightPrices(std::string value, std::vector<STG::DirPriceDataOpt> & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvPrice(&STG::DirPriceDataOpt::priceNightA, &STG::DirPriceDataOpt::priceNightB)));
+}
+
+STG::DirPriceDataOpt ConvThreshold(std::string value)
+{
+ STG::DirPriceDataOpt res;
+double threshold = 0;
+if (str2x(value, threshold) < 0)
+ throw SGCONF::ACTION::ERROR("Threshold should be a floating point value. Got: '" + value + "'");
+res.threshold = threshold;
+return res;
+}
+
+void ConvThresholds(std::string value, std::vector<STG::DirPriceDataOpt> & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvThreshold));
+}
+