import { TemplateService } from '../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../core/resources/index.js';
/**
 * A data source for the Template Query Builder that fetches data from the server
 * @class UmbTemplateQueryServerDataSource
 */
export class UmbTemplateQueryServerDataSource {
    #host;
    // TODO: When we map the server models to our own models, we need to have a localization property.
    // For example, the OperatorModel.NOT_EQUALS need to use the localization key "template_doesNotEqual"
    /**
     * Creates an instance of UmbTemplateQueryServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbTemplateQueryServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Fetches the query builder settings from the server
     * @returns {*}
     * @memberof UmbTemplateQueryServerDataSource
     */
    async getTemplateQuerySettings() {
        return tryExecute(this.#host, TemplateService.getTemplateQuerySettings());
    }
    /**
     * Executes a query builder query on the server
     * @param {UmbExecuteTemplateQueryRequestModel} args
     * @returns {*}
     * @memberof UmbTemplateQueryServerDataSource
     */
    async executeTemplateQuery(args) {
        const body = {
            rootDocument: args.rootDocument ? { id: args.rootDocument.unique } : null,
            documentTypeAlias: args.documentTypeAlias,
            filters: args.filters,
            sort: args.sort,
            take: args.take,
        };
        return tryExecute(this.#host, TemplateService.postTemplateQueryExecute({ body }));
    }
}
