import { UmbDocumentNotificationsServerDataSource } from './document-notifications.server.data.js';
import { UmbControllerBase } from '../../../../../../libs/class-api/index.js';
import { UMB_NOTIFICATION_CONTEXT } from '../../../../../core/notification/index.js';
import { UmbLocalizationController } from '../../../../../../libs/localization-api/index.js';
export class UmbDocumentNotificationsRepository extends UmbControllerBase {
    #dataSource = new UmbDocumentNotificationsServerDataSource(this);
    #notificationContext;
    #localize = new UmbLocalizationController(this);
    constructor(host) {
        super(host);
        this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
            this.#notificationContext = instance;
        });
    }
    async readNotifications(unique) {
        if (!unique)
            throw new Error('Unique is missing');
        const { data, error } = await this.#dataSource.read(unique);
        if (!error) {
            return { data };
        }
        return { error };
    }
    async updateNotifications(unique, documentName, data) {
        if (!unique)
            throw new Error('Unique is missing');
        if (!data)
            throw new Error('Data is missing');
        const { error } = await this.#dataSource.update(unique, data);
        if (!error) {
            const notification = {
                data: { message: this.#localize.term('notifications_notificationsSavedFor', documentName) },
            };
            this.#notificationContext?.peek('positive', notification);
        }
        return { error };
    }
}
export { UmbDocumentNotificationsRepository as api };
