import { UMB_USER_ENTITY_TYPE } from '../../entity.js';
import { UmbManagementApiUserItemDataRequestManager } from './user-item.server.request-manager.js';
import { UmbItemServerDataSourceBase } from '../../../../core/repository/index.js';
/**
 * A data source for user items that fetches data from the server
 * @class UmbUserItemServerDataSource
 * @implements {UmbItemDataSource}
 */
export class UmbUserItemServerDataSource extends UmbItemServerDataSourceBase {
    #itemRequestManager = new UmbManagementApiUserItemDataRequestManager(this);
    /**
     * Creates an instance of UmbUserItemServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbUserItemServerDataSource
     */
    constructor(host) {
        super(host, {
            mapper,
        });
    }
    async getItems(uniques) {
        if (!uniques)
            throw new Error('Uniques are missing');
        const { data, error } = await this.#itemRequestManager.getItems(uniques);
        return { data: this._getMappedItems(data), error };
    }
}
const mapper = (item) => {
    return {
        avatarUrls: item.avatarUrls,
        entityType: UMB_USER_ENTITY_TYPE,
        name: item.name,
        unique: item.id,
        kind: item.kind,
    };
};
