/* eslint-disable @typescript-eslint/no-extraneous-class */
import { CookieEventTypes } from './CookieEventTypes.js';
import { ContextEvent, ContextUpdateEvent, ContextStateUpdateEvent, } from '../BaseEvents.js';
export class CookieEvents {
    /**
     * Lists all projects in the data store.
     * This does not return the whole project record. Instead it only returns the index object of the project.
     *
     * @param target The target on which to dispatch the event
     * @returns The list of project index objects.
     */
    static async listAll(target = window) {
        const detail = {};
        const e = new CustomEvent(CookieEventTypes.listAll, {
            bubbles: true,
            composed: true,
            cancelable: true,
            detail,
        });
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * @param target The target on which to dispatch the event
     * @param domain The cookie domain
     * @returns The list of project index objects.
     */
    static async listDomain(domain, target = window) {
        const detail = { domain };
        const e = new ContextEvent(CookieEventTypes.listDomain, detail);
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * @param target The target on which to dispatch the event
     * @param url The cookie URL
     * @returns The list of project index objects.
     */
    static async listUrl(url, target = window) {
        const detail = { url };
        const e = new ContextEvent(CookieEventTypes.listUrl, detail);
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * Deletes cookies from the store.
     *
     * @param target The target on which to dispatch the event
     * @param cookies The list of cookies to remove
     */
    static async delete(cookies, target = window) {
        const detail = { cookies };
        const e = new ContextEvent(CookieEventTypes.delete, detail);
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * Deletes cookies from the store.
     *
     * @param target The target on which to dispatch the event
     * @param url The url associated with the cookie. Depending on the session mechanism
     *            the URL or the domain and the path is used.
     * @param name The name of the cookie to remove. When not set all cookies are removed for the given URL.
     */
    static async deleteUrl(url, name, target = window) {
        const detail = { url, name };
        const e = new ContextEvent(CookieEventTypes.deleteUrl, detail);
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * Updates a cookie in the store.
     *
     * @param target The target on which to dispatch the event
     * @param cookie A cookie to update
     * @returns The change record of the updated cookie.
     */
    static async update(cookie, target = window) {
        const e = new ContextUpdateEvent(CookieEventTypes.update, { item: cookie });
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * Updates a cookie in the store in a bulk operation.
     *
     * @param target The target on which to dispatch the event
     * @param cookies A list of cookies to update
     * @returns The change record of the updated cookie.
     */
    static async updateBulk(cookies, target = window) {
        const detail = { cookies };
        const e = new ContextEvent(CookieEventTypes.updateBulk, detail);
        target.dispatchEvent(e);
        return e.detail.result;
    }
    /**
     * Events related to a state of a cookie store.
     */
    static get State() {
        return StateEvents;
    }
}
class StateEvents {
    /**
     * Event dispatched when a cookie was deleted from the context store
     * @param target The target on which to dispatch the event
     * @param cookie The schema of the removed cookie
     */
    static delete(cookie, target = window) {
        const e = new CustomEvent(CookieEventTypes.State.delete, {
            bubbles: true,
            composed: true,
            cancelable: false,
            detail: { cookie },
        });
        target.dispatchEvent(e);
    }
    /**
     * Event dispatched when a cookie was deleted from the context store
     * @param target The target on which to dispatch the event
     * @param record The change record.
     */
    static update(record, target = window) {
        const e = new ContextStateUpdateEvent(CookieEventTypes.State.update, record);
        target.dispatchEvent(e);
    }
}
//# sourceMappingURL=CookieEvents.js.map