import { UmbDuplicateDocumentServerDataSource } from '../../../entity-actions/duplicate/repository/document-duplicate.server.data-source.js';
import { UmbRepositoryBase } from '../../../../../core/repository/index.js';
import { UMB_NOTIFICATION_CONTEXT } from '../../../../../core/notification/index.js';
export class UmbBulkDuplicateToDocumentRepository extends UmbRepositoryBase {
    #duplicateSource = new UmbDuplicateDocumentServerDataSource(this);
    async requestBulkDuplicateTo(args) {
        let count = 0;
        const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
        for (const unique of args.uniques) {
            const { error } = await this.#duplicateSource.duplicate({
                unique,
                destination: args.destination,
                relateToOriginal: args.relateToOriginal,
                includeDescendants: args.includeDescendants,
            });
            if (error) {
                const notification = { data: { message: error.message } };
                notificationContext?.peek('danger', notification);
            }
            else {
                count++;
            }
        }
        if (count > 0) {
            const notification = { data: { message: `Duplicated ${count} ${count === 1 ? 'document' : 'documents'}` } };
            notificationContext?.peek('positive', notification);
        }
        return {};
    }
}
export { UmbBulkDuplicateToDocumentRepository as api };
