import Cache from './cache.js';
import { fetchAPI } from './requests.js';
const cache = new Cache((itemType, itemId) => fetchAPI('GET', 'acl/:itemType/:itemId', {}, itemType, itemId), {
    ttl: 3600_000,
});
export async function updateACL(itemType, itemId, target, permissions) {
    const result = await fetchAPI('PATCH', 'acl/:itemType/:itemId', { target, permissions }, itemType, itemId);
    cache.invalidate(itemType, itemId);
    return result;
}
export async function getACL(itemType, itemId) {
    return await cache.get(itemType, itemId);
}
export async function addToACL(itemType, itemId, target) {
    const result = await fetchAPI('PUT', 'acl/:itemType/:itemId', target, itemType, itemId);
    cache.invalidate(itemType, itemId);
    return result;
}
export async function removeFromACL(itemType, itemId, target) {
    const result = await fetchAPI('DELETE', 'acl/:itemType/:itemId', target, itemType, itemId);
    cache.invalidate(itemType, itemId);
    return result;
}
