"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImageComparisonStatus = exports.triggerImageComparison = void 0;
var tslib_1 = require("tslib");
exports.triggerImageComparison = {
    rest: {
        method: 'POST',
        fullPath: '/api/pepsico-content/image-comparison/trigger/:recordId'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var logger, approvalId, triggerImageComparisonAsync, error_1;
            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;
                        approvalId = ctx.params.recordId;
                        _a.label = 2;
                    case 2:
                        _a.trys.push([2, 5, , 6]);
                        return [4, Promise.resolve().then(function () { return require('../methods/image_comparison'); })];
                    case 3:
                        triggerImageComparisonAsync = (_a.sent()).triggerImageComparisonAsync;
                        console.log("[API] \u624B\u52A8\u89E6\u53D1\u56FE\u7247\u5BF9\u6BD4: ".concat(approvalId));
                        return [4, triggerImageComparisonAsync(ctx, approvalId)];
                    case 4:
                        _a.sent();
                        return [2, {
                                success: true,
                                message: '图片对比任务已触发'
                            }];
                    case 5:
                        error_1 = _a.sent();
                        console.error("[API] \u89E6\u53D1\u56FE\u7247\u5BF9\u6BD4\u5931\u8D25: ".concat(approvalId), error_1.message);
                        return [2, {
                                success: false,
                                error: error_1.message
                            }];
                    case 6: return [2];
                }
            });
        });
    }
};
exports.getImageComparisonStatus = {
    rest: {
        method: 'GET',
        fullPath: '/api/pepsico-content/image-comparison/status/:recordId'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var approvalId, approval, error_2;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ctx.getObject = this.getObject;
                        approvalId = ctx.params.recordId;
                        _a.label = 1;
                    case 1:
                        _a.trys.push([1, 3, , 4]);
                        return [4, ctx.getObject('pepsico_material_approval').findOne(approvalId)];
                    case 2:
                        approval = _a.sent();
                        if (!approval) {
                            return [2, {
                                    success: false,
                                    error: '审批单不存在'
                                }];
                        }
                        return [2, {
                                success: true,
                                data: {
                                    status: approval.image_comparison_status,
                                    stats: approval.image_comparison_stats,
                                    comparedAt: approval.image_comparison_at
                                }
                            }];
                    case 3:
                        error_2 = _a.sent();
                        console.error("[API] \u83B7\u53D6\u56FE\u7247\u5BF9\u6BD4\u72B6\u6001\u5931\u8D25: ".concat(approvalId), error_2.message);
                        return [2, {
                                success: false,
                                error: error_2.message
                            }];
                    case 4: return [2];
                }
            });
        });
    }
};
//# sourceMappingURL=imageComparison.js.map