import { UMB_DATA_TYPE_ENTITY_TYPE } from '../entity.js';
import { DataTypeService } from '../../core/backend-api/index.js';
import { tryExecute } from '../../core/resources/index.js';
/**
 * A data source for the Rollback that fetches data from the server
 * @class UmbDataTypeSearchServerDataSource
 * @implements {RepositoryDetailDataSource}
 */
export class UmbDataTypeSearchServerDataSource {
    #host;
    /**
     * Creates an instance of UmbDataTypeSearchServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbDataTypeSearchServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Get a list of versions for a data
     * @param args
     * @returns {*}
     * @memberof UmbDataTypeSearchServerDataSource
     */
    async search(args) {
        const { data, error } = await tryExecute(this.#host, DataTypeService.getItemDataTypeSearch({
            query: {
                query: args.query,
                skip: args.paging?.skip,
                take: args.paging?.take,
            },
        }));
        if (data) {
            const mappedItems = data.items.map((item) => {
                return {
                    href: 'section/settings/workspace/data-type/edit/' + item.id,
                    entityType: UMB_DATA_TYPE_ENTITY_TYPE,
                    unique: item.id,
                    name: item.name,
                    propertyEditorSchemaAlias: item.editorAlias,
                    propertyEditorUiAlias: item.editorUiAlias || '',
                };
            });
            return { data: { items: mappedItems, total: data.total } };
        }
        return { error };
    }
}
