// (C) 2021-2023 GoodData Corporation
const {
    deleteTigerWorkspace
} = require('./fixture_tiger');

const { log } = require('./logger');
const { deleteVariableFromEnv } = require('./helpers/delete_helper');

const envFilePath = '.env';

async function deleteTigerReferenceWorkspace(
    host,
    tigerApiToken,
    testWorkspaceId,
    sdkBackend,
) {
    if (!tigerApiToken) {
        log('TIGER_API_TOKEN not specified in the .env file. Skipping.\n');
        return;
    }

    if (!testWorkspaceId) {
        log('WORKSPACE_ID not specified in the .env file. Skipping.\n');
        return;
    }

    await deleteTigerWorkspace(testWorkspaceId, tigerApiToken, host, sdkBackend);
    log(`Removing WORKSPACE_ID ${testWorkspaceId} from the .env file\n`);
    deleteVariableFromEnv(testWorkspaceId, envFilePath);
}

module.exports = {
    deleteTigerReferenceWorkspace
};
