"use strict";
/* tslint:disable class-name */
Object.defineProperty(exports, "__esModule", { value: true });
const WeightForPeriodRule_1 = require("../../../../rules/WeightForPeriodRule");
const ValidationException_1 = require("../../../../validation/ValidationException");
function wise_rule_weight_for_period_encode(rule) {
    let unit;
    if (rule.unit === WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.DAY)
        unit = "day";
    else if (rule.unit === WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.HOUR)
        unit = "hour";
    else if (rule.unit === WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.MINUTE)
        unit = "minute";
    else if (rule.unit === WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.SECOND)
        unit = "second";
    else
        throw new ValidationException_1.ValidationException("WeightForPeriodRule, unknown unit: " + rule.unit);
    const out = {
        rule: "weight_for_period",
        unit: unit,
        period: rule.period,
        weight: rule.weight
    };
    return out;
}
exports.wise_rule_weight_for_period_encode = wise_rule_weight_for_period_encode;
function wise_rule_weight_for_period_decode(r) {
    switch (r.unit) {
        case "day":
            return new WeightForPeriodRule_1.WeightForPeriodRule(r.period, WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.DAY, r.weight);
        case "hour":
            return new WeightForPeriodRule_1.WeightForPeriodRule(r.period, WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.HOUR, r.weight);
        case "minute":
            return new WeightForPeriodRule_1.WeightForPeriodRule(r.period, WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.MINUTE, r.weight);
        case "second":
            return new WeightForPeriodRule_1.WeightForPeriodRule(r.period, WeightForPeriodRule_1.WeightForPeriodRule.PeriodUnit.SECOND, r.weight);
        default:
            throw new ValidationException_1.ValidationException("V2 wise_rule_weight_for_period: Unknown period unit " + r.unit);
    }
}
exports.wise_rule_weight_for_period_decode = wise_rule_weight_for_period_decode;
//# sourceMappingURL=rule-weight-for-period-schema.js.map