import logger from '@adonisjs/core/services/logger';
import { genericListFilters } from './generic.js';
import { LIST_FILTER_SEPARATOR } from './index.js';
import { AKRegexListFilter } from './regex.js';
export class AKRelationListFilter extends AKRegexListFilter {
    constructor() {
        super(new RegExp(LIST_FILTER_SEPARATOR), (q, field, value, model) => {
            const [relationName, ...subComponents] = field.split(LIST_FILTER_SEPARATOR);
            const relation = model.$getRelation(relationName);
            if (!relation) {
                throw logger.warn(`RelationListFilter: Trying to filter on an unknown relation ${relationName} on ${model.name}`);
            }
            else {
                const transformSubQuery = (q, field) => genericListFilters
                    .find((f) => f.matches({ [field]: value }))
                    ?.apply(q, { [field]: value }, model);
                switch (relation.type) {
                    case 'hasOne':
                        return q;
                    case 'belongsTo':
                        return q.whereHas(relationName, (q) => transformSubQuery(q, subComponents.join(LIST_FILTER_SEPARATOR)));
                    case 'hasMany':
                        return q;
                    case 'manyToMany':
                        return q;
                    case 'hasManyThrough':
                        return q;
                }
            }
        });
    }
}
//# sourceMappingURL=relation.js.map