"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPpDomainListInOnmDomainId = void 0;
const shell_1 = require("@things-factory/shell");
const onm_domain_binding_1 = require("./onm-domain-binding");
const typeorm_1 = require("typeorm");
const getPpDomainListInOnmDomainId = (params) => {
    const { onmDomainId, listParams } = params;
    const nameSearch = listParams.filters.find(v => v.name === 'name');
    const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
        params: listParams,
        repository: (0, shell_1.getRepository)(onm_domain_binding_1.OnmDomainBinding),
        alias: 'odb'
    })
        .leftJoinAndSelect('odb.powerPlantDomain', 'd_pp')
        .leftJoinAndSelect('odb.onmDomain', 'd_onm')
        .where('odb.onm_domain_id = :onmDomainId', { onmDomainId })
        .orderBy('d_pp.name', 'ASC');
    if (nameSearch) {
        queryBuilder.andWhere(new typeorm_1.Brackets(qb => {
            qb.where('d_pp.name ILIKE :name', { name: `%${nameSearch.value}%` });
            qb.orWhere('d_pp.description ILIKE :description', { description: `%${nameSearch.value}%` });
        }));
    }
    return queryBuilder;
};
exports.getPpDomainListInOnmDomainId = getPpDomainListInOnmDomainId;
//# sourceMappingURL=onm-domain-binding-repository.js.map