"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.submit = void 0;
var tslib_1 = require("tslib");
var lodash_1 = require("lodash");
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, approvalNew, _a;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        ctx.getObject = this.getObject;
                        return [4, this.getLogger()];
                    case 1:
                        logger = _b.sent();
                        ctx.logger = logger;
                        return [4, ctx.getObject('pepsico_material_approval').findOne(ctx.params.recordId)];
                    case 2:
                        approval = _b.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 = _b.sent();
                        return [4, ctx.getObject('pepsico_material_approval').directUpdate(ctx.params.recordId, {
                                pepsico_flow_rule: rule._id
                            })];
                    case 4:
                        _b.sent();
                        _b.label = 5;
                    case 5:
                        if (approval.current_step === consts_1.Step.submitter_revisions && (approval.classification == '22335110412927067-22335110412927093' || approval.classification == '22335110412927067-22335110412927078' || approval.classification == '22335110412927067-22335110412927088' || approval.classification == '22335110412927067-22335110412927093' || approval.classification == '22335110412927067-22335110412927108' || approval.classification == '22335110412927165' || approval.classification == '22335110412927191' || approval.classification == '22335110412927128') && approval.legal_approval_status === false) {
                            if (approval.is_trademark_checked == 'no' && (0, lodash_1.isEmpty)(approval.trademark_files)) {
                                return [2, {
                                        status: 500,
                                        msg: '请先上传商标检索文件，再提交审批.',
                                        data: {}
                                    }];
                            }
                        }
                        if (!(approval.current_step === consts_1.Step.submitter_revisions)) return [3, 7];
                        return [4, ctx.getObject('pepsico_material_approval').directUpdate(ctx.params.recordId, {
                                recent_edit_comment: ctx.params.comment,
                                recent_submit_time: new Date(),
                                $inc: {
                                    submit_time: 1
                                }
                            })];
                    case 6:
                        _b.sent();
                        _b.label = 7;
                    case 7:
                        console.time('submitContent: ' + ctx.params.recordId);
                        return [4, this.submitContent(ctx, ctx.params.recordId, ctx.params.approvalStatus, ctx.params.skip)];
                    case 8:
                        _b.sent();
                        console.timeEnd('submitContent: ' + ctx.params.recordId);
                        return [4, ctx.getObject('pepsico_material_approval').findOne(ctx.params.recordId)];
                    case 9:
                        approvalNew = _b.sent();
                        console.log("approvalNew.current_step", approvalNew.current_step, consts_1.Step.ai_review);
                        if (!(approvalNew.current_step === consts_1.Step.ai_review)) return [3, 12];
                        console.log("submitContent=====");
                        _a = ctx.meta;
                        return [4, ctx.broker.call("@steedos/service-accounts.getUserSession", {
                                userId: ctx.meta.user.space.admins[0],
                                spaceId: ctx.meta.user.spaceId
                            })];
                    case 10:
                        _a.user = _b.sent();
                        return [4, this.submitContent(ctx, ctx.params.recordId, 'approved', true)];
                    case 11:
                        _b.sent();
                        _b.label = 12;
                    case 12: return [2, {}];
                }
            });
        });
    }
};
//# sourceMappingURL=submit.js.map