import { DocumentService } from '../../../../core/backend-api/index.js';
import { UmbItemServerDataSourceBase } from '../../../../core/repository/index.js';
import { UmbItemDataApiGetRequestController } from '../../../../core/entity-item/index.js';
/**
 * A server data source for Document URLs
 * @class UmbDocumentUrlServerDataSource
 * @implements {DocumentTreeDataSource}
 */
export class UmbDocumentUrlServerDataSource extends UmbItemServerDataSourceBase {
    /**
     * Creates an instance of UmbDocumentUrlServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbDocumentUrlServerDataSource
     */
    constructor(host) {
        super(host, { mapper });
    }
    async getItems(uniques) {
        if (!uniques)
            throw new Error('Uniques are missing');
        const itemRequestManager = new UmbItemDataApiGetRequestController(this, {
            // eslint-disable-next-line local-rules/no-direct-api-import
            api: (args) => DocumentService.getDocumentUrls({ query: { id: args.uniques } }),
            uniques,
        });
        const { data, error } = await itemRequestManager.request();
        return { data: this._getMappedItems(data), error };
    }
}
const mapper = (item) => ({
    unique: item.id,
    urls: item.urlInfos.map((urlInfo) => ({ culture: urlInfo.culture, url: urlInfo.url ?? undefined })),
});
