import { UMB_WEBHOOK_ENTITY_TYPE } from '../../../entity.js';
import { UmbItemServerDataSourceBase } from '../../../../core/repository/index.js';
import { WebhookService } from '../../../../core/backend-api/index.js';
import { UmbItemDataApiGetRequestController } from '../../../../core/entity-item/index.js';
/**
 * A server data source for Webhook items
 * @class UmbWebhookItemServerDataSource
 * @implements {UmbItemServerDataSourceBase}
 */
export class UmbWebhookItemServerDataSource extends UmbItemServerDataSourceBase {
    /**
     * Creates an instance of UmbWebhookItemServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbWebhookItemServerDataSource
     */
    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) => WebhookService.getItemWebhook({ query: { id: args.uniques } }),
            uniques,
        });
        const { data, error } = await itemRequestManager.request();
        return { data: this._getMappedItems(data), error };
    }
}
const mapper = (item) => {
    return {
        unique: item.id,
        name: item.name,
        entityType: UMB_WEBHOOK_ENTITY_TYPE,
    };
};
