#include eeprom/script.jsx

const MamiEEPROM = function(baseUrl, getAuthLine) {
    if(typeof baseUrl !== 'string')
        throw 'baseUrl must be a string';
    if(typeof getAuthLine !== 'function')
        throw 'getAuthLine must be a function';

    // when the pools rewrite happen, retrieve this from futami common
    const appId = '1';
    let client;

    return {
        get client() {
            return client;
        },

        init: async () => {
            await MamiEEPROMLoadScript(baseUrl);
            client = new EEPROM(appId, baseUrl, getAuthLine);
        },

        create: fileInput => {
            if(client === undefined)
                throw 'eeprom client is uninitialised';

            return client.create(fileInput);
        },

        delete: async fileInfo => {
            if(client === undefined)
                throw 'eeprom client is uninitialised';

            await client.delete(fileInfo);
        },
    };
};
