import { MediaService } from '../../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../../core/resources/index.js';
/**
 * A server data source for sorting children of a Media
 * @class UmbSortChildrenOfMediaServerDataSource
 * @implements {RepositoryDetailDataSource}
 */
export class UmbSortChildrenOfMediaServerDataSource {
    #host;
    /**
     * Creates an instance of UmbSortChildrenOfMediaServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbSortChildrenOfMediaServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Creates the Public Access for the given Media unique
     * @param {UmbSortChildrenOfArgs} args
     * @memberof UmbSortChildrenOfMediaServerDataSource
     */
    async sortChildrenOf(args) {
        if (args.unique === undefined)
            throw new Error('unique is missing');
        const sortingMapping = args.sorting.map((item) => ({ id: item.unique, sortOrder: item.sortOrder }));
        return tryExecute(this.#host, MediaService.putMediaSort({
            body: {
                parent: args.unique ? { id: args.unique } : null,
                sorting: sortingMapping,
            },
        }));
    }
}
