import assert from 'node:assert';
import BoxError from './boxerror.js';
import tgzFormat from './backupformat/tgz.js';
import rsyncFormat from './backupformat/rsync.js';


const FORMATS = { tgz: tgzFormat, rsync: rsyncFormat };

function api(format) {
    assert.strictEqual(typeof format, 'string');

    if (FORMATS[format]) return FORMATS[format];

    throw new BoxError(BoxError.INTERNAL_ERROR, `Undefined format ${format}`);
}

function validateFormat(format) {
    assert.strictEqual(typeof format, 'string');

    if (format === 'tgz' || format == 'rsync') return null;

    return new BoxError(BoxError.BAD_FIELD, 'Invalid backup format');
}

export default {
    api,
    validateFormat,
};
