"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnalysisQuery = exports.ProcessQuery = void 0;
const tslib_1 = require("tslib");
require("@things-factory/auth-base"); /* for Resolver Context */
const type_graphql_1 = require("type-graphql");
const shell_1 = require("@things-factory/shell");
const integration_base_1 = require("@things-factory/integration-base");
const analysis_1 = require("./analysis");
const process_1 = require("../process/process");
const analysis_type_1 = require("./analysis-type");
let ProcessQuery = class ProcessQuery {
    async analysis(process) {
        return await (0, shell_1.getRepository)(analysis_1.Analysis).findOneBy({ process: { id: process.id } });
    }
};
exports.ProcessQuery = ProcessQuery;
tslib_1.__decorate([
    (0, type_graphql_1.FieldResolver)(type => analysis_1.Analysis),
    tslib_1.__param(0, (0, type_graphql_1.Root)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [process_1.Process]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessQuery.prototype, "analysis", null);
exports.ProcessQuery = ProcessQuery = tslib_1.__decorate([
    (0, type_graphql_1.Resolver)(process_1.Process)
], ProcessQuery);
let AnalysisQuery = class AnalysisQuery {
    async analysis(id, context) {
        return await (0, shell_1.getRepository)(analysis_1.Analysis).findOne({
            where: { id }
        });
    }
    async checkAnalysisAvailability(id, context) {
        var analysis = {
            process: { id: id }
        };
        const repository = (0, shell_1.getRepository)(analysis_1.Analysis);
        analysis = (await repository.findOneBy(analysis)) || analysis;
        return {
            result: (analysis === null || analysis === void 0 ? void 0 : analysis.availiability) || false,
            detail: (analysis === null || analysis === void 0 ? void 0 : analysis.availDetail) || ''
        };
    }
    async downloadLevel1AnalysisReport(id, context) {
        var _a, _b;
        const scenarioName = '레벨1 PDF 리포트';
        const result = await (0, integration_base_1.runScenario)(null, scenarioName, {
            processId: id
        }, context);
        return (_b = (_a = result === null || result === void 0 ? void 0 : result.result) === null || _a === void 0 ? void 0 : _a.save) === null || _b === void 0 ? void 0 : _b.fullpath;
    }
    async downloadLevel2AnalysisReport(inputs, context) {
        var _a, _b;
        const scenarioName = '레벨2 PDF 리포트';
        const result = await (0, integration_base_1.runScenario)(null, scenarioName, Object.assign({}, inputs), context);
        return (_b = (_a = result === null || result === void 0 ? void 0 : result.result) === null || _a === void 0 ? void 0 : _a.save) === null || _b === void 0 ? void 0 : _b.fullpath;
    }
};
exports.AnalysisQuery = AnalysisQuery;
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => analysis_1.Analysis, { nullable: true, description: 'To fetch a Analysis' }),
    tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
    tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], AnalysisQuery.prototype, "analysis", null);
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => analysis_type_1.AnalysisAvailability, { description: 'To check the availability of a Analysis dag' }),
    tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
    tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], AnalysisQuery.prototype, "checkAnalysisAvailability", null);
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => String, { description: 'To download the Analysis report for Level 1 as a PDF file' }),
    tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
    tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], AnalysisQuery.prototype, "downloadLevel1AnalysisReport", null);
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => String, { description: 'To download the Analysis report for Level 2 as a PDF file' }),
    tslib_1.__param(0, (0, type_graphql_1.Arg)('inputs', type => shell_1.ScalarObject)),
    tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], AnalysisQuery.prototype, "downloadLevel2AnalysisReport", null);
exports.AnalysisQuery = AnalysisQuery = tslib_1.__decorate([
    (0, type_graphql_1.Resolver)(analysis_1.Analysis)
], AnalysisQuery);
//# sourceMappingURL=analysis-query.js.map