async function getOldestPrivatriids(dbName, storeName) {
    return new Promise((resolve, reject) => {
        const request = indexedDB.open(dbName, 1);

        request.onsuccess = (event) => {
            const db = event.target.result;

            const transaction = db.transaction(storeName, "readonly");
            const store = transaction.objectStore(storeName);
            const cursorRequest = store.openCursor();
            const uuidMap = {};

            cursorRequest.onsuccess = (event) => {
                const cursor = event.target.result;
                if (cursor) {
                    const obj = cursor.value;

                    const [uuid, timestamp] = obj.privatriid.split("_");

                    if (!uuidMap[uuid] || Number(timestamp) < uuidMap[uuid].timestamp) {
                        uuidMap[uuid] = { privatriid: obj.privatriid, timestamp: Number(timestamp) };
                    };

                    cursor.continue();
                } else {
                    const result = Object.values(uuidMap).map(event => event.privatriid);
                    
                    resolve(result);
                };
            };

            cursorRequest.onerror = (event) => reject(event);
        };

        request.onerror = (event) => reject(event);
    });
};

async function syncronizeBackend(lastConnection) {
    
};

export {
    getOldestPrivatriids,
    syncronizeBackend
};