"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.submit = void 0;
var tslib_1 = require("tslib");
var methods_1 = require("../methods");
var consts_1 = require("../methods/consts");
exports.submit = {
    rest: {
        method: 'POST',
        fullPath: '/api/pepsico-content/approve/submit/:recordId'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var logger, approval, rule;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ctx.getObject = this.getObject;
                        return [4, this.getLogger()];
                    case 1:
                        logger = _a.sent();
                        ctx.logger = logger;
                        return [4, ctx.getObject('pepsico_material_approval').findOne(ctx.params.recordId)];
                    case 2:
                        approval = _a.sent();
                        if (!(approval.current_step === consts_1.Step.draft && approval.kol_classification != 'non-top' && approval.kol_classification != 'top')) return [3, 5];
                        return [4, (0, methods_1.getDefApproverStepRule)(ctx)];
                    case 3:
                        rule = _a.sent();
                        return [4, ctx.getObject('pepsico_material_approval').directUpdate(ctx.params.recordId, {
                                pepsico_flow_rule: rule._id
                            })];
                    case 4:
                        _a.sent();
                        _a.label = 5;
                    case 5:
                        console.time('submitContent: ' + ctx.params.recordId);
                        return [4, this.submitContent(ctx, ctx.params.recordId, ctx.params.approvalStatus, ctx.params.skip)];
                    case 6:
                        _a.sent();
                        console.timeEnd('submitContent: ' + ctx.params.recordId);
                        return [2, {}];
                }
            });
        });
    }
};
//# sourceMappingURL=submit.js.map