import { UmbMediaServerDataSource } from './media-detail.server.data-source.js';
import { UMB_MEDIA_DETAIL_STORE_CONTEXT } from './media-detail.store.context-token.js';
import { UmbImagingRepository } from '../../../imaging/index.js';
import { UmbDetailRepositoryBase } from '../../../../core/repository/index.js';
export class UmbMediaDetailRepository extends UmbDetailRepositoryBase {
    #imagingRepository = new UmbImagingRepository(this);
    constructor(host) {
        super(host, UmbMediaServerDataSource, UMB_MEDIA_DETAIL_STORE_CONTEXT);
    }
    /**
     * Creates a media item without showing automatic error notifications.
     * Error handling is left to the caller (e.g. the dropzone manager).
     */
    async createSilently(model, parentUnique) {
        if (!model)
            throw new Error('Data is missing');
        return this.detailDataSource.create(model, parentUnique, true);
    }
    /**
     * @inheritdoc
     */
    async save(model) {
        const result = await super.save(model);
        if (!result.error) {
            // Attempt to clear image cache
            await this.#imagingRepository._internal_clearCropByUnique(model.unique);
        }
        return result;
    }
    /**
     * @inheritdoc
     */
    async delete(unique) {
        const result = await super.delete(unique);
        if (!result.error) {
            // Attempt to clear image cache
            await this.#imagingRepository._internal_clearCropByUnique(unique);
        }
        return result;
    }
}
export { UmbMediaDetailRepository as api };
export default UmbMediaDetailRepository;
