"use strict";
/* tslint:disable class-name */
Object.defineProperty(exports, "__esModule", { value: true });
const AgeOfPostRule_1 = require("../../../../rules/AgeOfPostRule");
const ValidationException_1 = require("../../../../validation/ValidationException");
function wise_rule_age_of_post_encode(r) {
    let mode;
    if (r.mode === AgeOfPostRule_1.AgeOfPostRule.Mode.OLDER_THAN)
        mode = "older_than";
    else if (r.mode === AgeOfPostRule_1.AgeOfPostRule.Mode.YOUNGER_THAN)
        mode = "younger_than";
    else
        throw new ValidationException_1.ValidationException("AgeOfPost rule, unknown mode: " + r.mode);
    let unit;
    if (r.unit === AgeOfPostRule_1.AgeOfPostRule.TimeUnit.DAY)
        unit = "day";
    else if (r.unit === AgeOfPostRule_1.AgeOfPostRule.TimeUnit.HOUR)
        unit = "hour";
    else if (r.unit === AgeOfPostRule_1.AgeOfPostRule.TimeUnit.MINUTE)
        unit = "minute";
    else if (r.unit === AgeOfPostRule_1.AgeOfPostRule.TimeUnit.SECOND)
        unit = "second";
    else
        throw new ValidationException_1.ValidationException("AgeOfPostRule, unknown unit: " + r.unit);
    const out = {
        rule: "age_of_post",
        mode: mode,
        unit: unit,
        value: r.value
    };
    return out;
}
exports.wise_rule_age_of_post_encode = wise_rule_age_of_post_encode;
function wise_rule_age_of_post_decode(r) {
    let mode;
    if (r.mode === "older_than")
        mode = AgeOfPostRule_1.AgeOfPostRule.Mode.OLDER_THAN;
    else if (r.mode === "younger_than")
        mode = AgeOfPostRule_1.AgeOfPostRule.Mode.YOUNGER_THAN;
    else
        throw new ValidationException_1.ValidationException("v2:wise_rule_age_of_post: unknown mode " + r.mode);
    let unit;
    if (r.unit === "day")
        unit = AgeOfPostRule_1.AgeOfPostRule.TimeUnit.DAY;
    else if (r.unit === "hour")
        unit = AgeOfPostRule_1.AgeOfPostRule.TimeUnit.HOUR;
    else if (r.unit === "minute")
        unit = AgeOfPostRule_1.AgeOfPostRule.TimeUnit.MINUTE;
    else if (r.unit === "second")
        unit = AgeOfPostRule_1.AgeOfPostRule.TimeUnit.SECOND;
    else
        throw new ValidationException_1.ValidationException("v2:wise_rule_age_of_post: unknown unit " + r.unit);
    return new AgeOfPostRule_1.AgeOfPostRule(mode, r.value, unit);
}
exports.wise_rule_age_of_post_decode = wise_rule_age_of_post_decode;
//# sourceMappingURL=rule-age-of-post-schema.js.map