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