import { UmbRepositoryBase } from '../../repository/index.js';
export class UmbRenameServerFileRepositoryBase extends UmbRepositoryBase {
    #renameSource;
    #detailStoreContextAlias;
    constructor(host, detailSource, detailStoreContextAlias) {
        super(host);
        this.#renameSource = new detailSource(host);
        this.#detailStoreContextAlias = detailStoreContextAlias;
    }
    /**
     * Rename
     * @param {string} unique
     * @param {string} name
     * @returns {*}
     * @memberof UmbRenameServerFileRepositoryBase
     */
    async rename(unique, name) {
        if (!unique)
            throw new Error('Unique is missing');
        if (!name)
            throw new Error('Name is missing');
        const { data, error } = await this.#renameSource.rename(unique, name);
        if (data) {
            const detailStore = await this.getContext(this.#detailStoreContextAlias);
            if (!detailStore)
                throw new Error('Detail store is missing');
            /* When renaming a file the unique changed because it is based on the path/name
            We need to remove the old item and append the new item */
            detailStore.removeItem(unique);
            detailStore.append(data);
        }
        return { data, error };
    }
}
