import { UMB_MEDIA_TYPE_ENTITY_TYPE } from '../entity.js';
import { MediaTypeService } 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 UmbMediaTypeSearchServerDataSource
 * @implements {RepositoryDetailDataSource}
 */
export class UmbMediaTypeSearchServerDataSource {
    #host;
    /**
     * Creates an instance of UmbMediaTypeSearchServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbMediaTypeSearchServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Get a list of versions for a data
     * @param args
     * @returns {*}
     * @memberof UmbMediaTypeSearchServerDataSource
     */
    async search(args) {
        const { data, error } = await tryExecute(this.#host, MediaTypeService.getItemMediaTypeSearch({
            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/media-type/edit/' + item.id,
                    entityType: UMB_MEDIA_TYPE_ENTITY_TYPE,
                    unique: item.id,
                    name: item.name,
                    icon: item.icon || null,
                };
            });
            return { data: { items: mappedItems, total: data.total } };
        }
        return { error };
    }
}
