import { DocumentService } from '../../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../../core/resources/index.js';
/**
 * Duplicate Document Server Data Source
 * @class UmbDuplicateDocumentServerDataSource
 */
export class UmbDuplicateDocumentServerDataSource {
    #host;
    /**
     * Creates an instance of UmbDuplicateDocumentServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbDuplicateDocumentServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Duplicate an item for the given id to the destination unique
     * @param {UmbDuplicateDocumentRequestArgs} args
     * @returns {*}
     * @memberof UmbDuplicateDocumentServerDataSource
     */
    async duplicate(args) {
        if (!args.unique)
            throw new Error('Unique is missing');
        if (args.destination.unique === undefined)
            throw new Error('Destination unique is missing');
        return tryExecute(this.#host, DocumentService.postDocumentByIdCopy({
            path: { id: args.unique },
            body: {
                target: args.destination.unique ? { id: args.destination.unique } : null,
                relateToOriginal: args.relateToOriginal,
                includeDescendants: args.includeDescendants,
            },
        }), { disableNotifications: true });
    }
}
