import { UmbDocumentPublicAccessServerDataSource } from './public-access.server.data.js';
import { UmbControllerBase } from '../../../../libs/class-api/index.js';
import { UMB_NOTIFICATION_CONTEXT } from '../../../core/notification/index.js';
export class UmbDocumentPublicAccessRepository extends UmbControllerBase {
    #dataSource = new UmbDocumentPublicAccessServerDataSource(this);
    #notificationContext;
    constructor(host) {
        super(host);
        this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
            this.#notificationContext = instance;
        });
    }
    async create(unique, data) {
        if (!unique)
            throw new Error('unique is missing');
        if (!data)
            throw new Error('Data is missing');
        const { error } = await this.#dataSource.create(unique, data);
        if (!error) {
            const notification = { data: { message: `Public access setting created` } };
            this.#notificationContext?.peek('positive', notification);
        }
        return { error };
    }
    async read(unique, includeAncestors = false) {
        if (!unique)
            throw new Error('unique is missing');
        const { data, error } = await this.#dataSource.read(unique, includeAncestors);
        return { data, error };
    }
    async update(unique, 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: `Public access setting updated` } };
            this.#notificationContext?.peek('positive', notification);
        }
        return { error };
    }
    async delete(unique) {
        if (!unique)
            throw new Error('unique is missing');
        const { error } = await this.#dataSource.delete(unique);
        if (!error) {
            const notification = { data: { message: `Public access setting deleted` } };
            this.#notificationContext?.peek('positive', notification);
        }
        return { error };
    }
}
export { UmbDocumentPublicAccessRepository as api };
