import assert from 'node:assert';
import BoxError from '../boxerror.js';

// -------------------------------------------
//  This file just describes the interface
//
//  New backends can start from here
// -------------------------------------------


function removePrivateFields(domainObject) {
    // in-place removal of tokens and api keys
    return domainObject;
}

// eslint-disable-next-line no-unused-vars
function injectPrivateFields(newConfig, currentConfig) {
    // in-place injection of tokens and api keys
}

// replaces any existing records or creates new records of subdomain+type with values
async function upsert(domainObject, subdomain, type, values) {
    assert.strictEqual(typeof domainObject, 'object');
    assert.strictEqual(typeof subdomain, 'string');
    assert.strictEqual(typeof type, 'string');
    assert(Array.isArray(values));

    // Result: none

    throw new BoxError(BoxError.NOT_IMPLEMENTED, 'upsert is not implemented');
}

// NOTE: returns empty array when there are no records
async function get(domainObject, subdomain, type) {
    assert.strictEqual(typeof domainObject, 'object');
    assert.strictEqual(typeof subdomain, 'string');
    assert.strictEqual(typeof type, 'string');

    // Result: Array of matching DNS records in string format

    throw new BoxError(BoxError.NOT_IMPLEMENTED, 'get is not implemented');
}

// must only delete records that match values
async function del(domainObject, subdomain, type, values) {
    assert.strictEqual(typeof domainObject, 'object');
    assert.strictEqual(typeof subdomain, 'string');
    assert.strictEqual(typeof type, 'string');
    assert(Array.isArray(values));

    // Result: none

    throw new BoxError(BoxError.NOT_IMPLEMENTED, 'del is not implemented');
}

async function wait(domainObject, subdomain, type, value, options) {
    assert.strictEqual(typeof domainObject, 'object');
    assert.strictEqual(typeof subdomain, 'string');
    assert.strictEqual(typeof type, 'string');
    assert.strictEqual(typeof value, 'string');
    assert(options && typeof options === 'object'); // { interval: 5000, times: 50000 }
}

async function verifyDomainConfig(domainObject) {
    assert.strictEqual(typeof domainObject, 'object');

    // Result: domainConfig object

    throw new BoxError(BoxError.NOT_IMPLEMENTED, 'verifyDomainConfig is not implemented');
}

export default {
    removePrivateFields,
    injectPrivateFields,
    upsert,
    get,
    del,
    wait,
    verifyDomainConfig
};
