import { MediaService } from '../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../core/resources/index.js';
export class UmbMediaRecycleBinServerDataSource {
    #host;
    constructor(host) {
        this.#host = host;
    }
    trash(args) {
        return tryExecute(this.#host, MediaService.putMediaByIdMoveToRecycleBin({ path: { id: args.unique } }));
    }
    restore(args) {
        return tryExecute(this.#host, MediaService.putRecycleBinMediaByIdRestore({
            path: { id: args.unique },
            body: {
                target: args.destination.unique ? { id: args.destination.unique } : null,
            },
        }));
    }
    empty() {
        return tryExecute(this.#host, MediaService.deleteRecycleBinMedia());
    }
    async getOriginalParent(args) {
        const { data, error } = await tryExecute(this.#host, MediaService.getRecycleBinMediaByIdOriginalParent({ path: { id: args.unique } }));
        // only check for undefined because data can be null if the parent is the root
        if (data !== undefined) {
            const mappedData = data ? { unique: data.id } : null;
            return { data: mappedData };
        }
        return { error };
    }
}
