"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDownloadMaterialsProgress = exports.getUploadMaterialsProgress = void 0;
var tslib_1 = require("tslib");
exports.getUploadMaterialsProgress = {
    rest: {
        method: 'GET',
        fullPath: '/api/pepsico-content/approve/:approveId/material/upload/progress'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var logger, materials, pendingMaterials;
            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, this.getOneDriveMaterials(ctx, ctx.params.approveId)];
                    case 2:
                        materials = _a.sent();
                        if (materials.length < 1) {
                            return [2, { progress: 100 }];
                        }
                        pendingMaterials = materials.filter(function (material) {
                            return material.uploaded_to_onedrive !== true;
                        });
                        return [2, {
                                progress: Math.round((1 - pendingMaterials.length / materials.length) * 100)
                            }];
                }
            });
        });
    }
};
exports.getDownloadMaterialsProgress = {
    rest: {
        method: 'GET',
        fullPath: '/api/pepsico-content/approve/:approveId/material/download/progress'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var logger, materials, pendingMaterials;
            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, this.getOneDriveMaterials(ctx, ctx.params.approveId)];
                    case 2:
                        materials = _a.sent();
                        if (materials.length < 1) {
                            return [2, { progress: 100 }];
                        }
                        pendingMaterials = materials.filter(function (material) {
                            return material.download_from_onedrive !== true;
                        });
                        return [2, {
                                progress: Math.round((1 - pendingMaterials.length / materials.length) * 100)
                            }];
                }
            });
        });
    }
};
//# sourceMappingURL=progress.js.map