"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProcessGroupQuery = void 0;
const tslib_1 = require("tslib");
const type_graphql_1 = require("type-graphql");
const auth_base_1 = require("@things-factory/auth-base");
const shell_1 = require("@things-factory/shell");
const process_1 = require("../process/process");
const process_group_1 = require("./process-group");
const process_group_type_1 = require("./process-group-type");
let ProcessGroupQuery = class ProcessGroupQuery {
    async processGroup(id, context) {
        const { domain } = context.state;
        return await (0, shell_1.getRepository)(process_group_1.ProcessGroup).findOne({
            where: { domain: { id: domain.id }, id }
        });
    }
    async processGroups(params, context) {
        const { domain } = context.state;
        const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
            repository: (0, shell_1.getRepository)(process_group_1.ProcessGroup),
            params,
            domain,
            searchables: ['name', 'description']
        });
        const [items, total] = await queryBuilder.getManyAndCount();
        return { items, total };
    }
    async processes(group) {
        return await (0, shell_1.getRepository)(process_1.Process).findBy({
            group: { id: group.id }
        });
    }
    async domain(group) {
        return await (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: group.domainId });
    }
    async updater(group) {
        return await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: group.updaterId });
    }
    async creator(group) {
        return await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: group.creatorId });
    }
};
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => process_group_1.ProcessGroup, { nullable: true, description: 'To fetch a ProcessGroup' }),
    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)
], ProcessGroupQuery.prototype, "processGroup", null);
tslib_1.__decorate([
    (0, type_graphql_1.Query)(returns => process_group_type_1.ProcessGroupList, { description: 'To fetch multiple ProcessGroups' }),
    tslib_1.__param(0, (0, type_graphql_1.Args)()),
    tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessGroupQuery.prototype, "processGroups", null);
tslib_1.__decorate([
    (0, type_graphql_1.FieldResolver)(type => [process_1.Process]),
    tslib_1.__param(0, (0, type_graphql_1.Root)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [process_group_1.ProcessGroup]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessGroupQuery.prototype, "processes", null);
tslib_1.__decorate([
    (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
    tslib_1.__param(0, (0, type_graphql_1.Root)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [process_group_1.ProcessGroup]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessGroupQuery.prototype, "domain", null);
tslib_1.__decorate([
    (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
    tslib_1.__param(0, (0, type_graphql_1.Root)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [process_group_1.ProcessGroup]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessGroupQuery.prototype, "updater", null);
tslib_1.__decorate([
    (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
    tslib_1.__param(0, (0, type_graphql_1.Root)()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [process_group_1.ProcessGroup]),
    tslib_1.__metadata("design:returntype", Promise)
], ProcessGroupQuery.prototype, "creator", null);
ProcessGroupQuery = tslib_1.__decorate([
    (0, type_graphql_1.Resolver)(process_group_1.ProcessGroup)
], ProcessGroupQuery);
exports.ProcessGroupQuery = ProcessGroupQuery;
//# sourceMappingURL=process-group-query.js.map