import { DBExportEndpoint, DBImportEndpoint, DBImportRequest, DBWipeEndpoint } from "../../api/api";
import backendRequest from "./request";

export function getDBExportLink() {
    return (process.env.REACT_APP_BACKEND || "") + DBExportEndpoint;
}

export async function wipeDB() {
    const requestOpts = {
        method: 'POST'
    };

    const response = await backendRequest((process.env.REACT_APP_BACKEND || "") + DBWipeEndpoint, requestOpts)
    if (!response.ok) {
        throw new Error("Response to DB wipe not OK: " + JSON.stringify(response));
    }

    return;
}

export async function importDB(jsonData: DBImportRequest) {
    const requestOpts = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(jsonData),
    };

    const response = await backendRequest((process.env.REACT_APP_BACKEND || "") + DBImportEndpoint, requestOpts)
    if (!response.ok) {
        throw new Error("Response to DB import not OK: " + JSON.stringify(response));
    }
}