"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const Rule_1 = require("./Rule");
const ValidationException_1 = require("../validation/ValidationException");
const util_1 = require("../util/util");
/**
 * This rule limits maximal or minimal weight of single vote.
 * Negative values means flag, while positive means upvote.
 */
class FirstPostRule extends Rule_1.Rule {
    constructor() {
        super();
        this.rule = Rule_1.Rule.Type.FirstPost;
    }
    type() {
        return Rule_1.Rule.Type.FirstPost;
    }
    validate(voteorder, context) {
        return __awaiter(this, void 0, void 0, function* () {
            this.validateRuleObject(this);
            const entries = yield context.getBlogEntries(voteorder.author, 0, 250);
            const oldestEntry = util_1.Util.definedOrThrow(_.last(entries), new ValidationException_1.ValidationException("This author (" + voteorder.author + ") has no blog entries."));
            if (oldestEntry.entry_id !== 0)
                throw new ValidationException_1.ValidationException("This author already has more than 250 blog entries.");
            else {
                if (oldestEntry.author !== voteorder.author || oldestEntry.permlink !== voteorder.permlink) {
                    throw new ValidationException_1.ValidationException("This is not the first post of this author");
                }
            }
        });
    }
    validateRuleObject(unprototypedObj) {
    }
    getDescription() {
        return "First post of the author";
    }
}
exports.FirstPostRule = FirstPostRule;
//# sourceMappingURL=FirstPostRule.js.map