import axios from "axios";
import type { Pod } from "~/classes/Pod";

export function getPods(namespace: string | undefined, onSuccess: (pods: Pod[]) => void)
{
    axios.get<Pod[]>(useRuntimeConfig().public.apiBase + '/pods', {
        headers: {
            Authorization: "Bearer " + requireToken()
        },
        params: getParams(namespace)
    })
    .then((response) => {
        onSuccess(response.data);
    })
    .catch();
}

export function deletePod(namespace: string, name: string, onSuccess: () => void)
{
    axios.delete(StringUtils.format('%s/pods/%s/%s', useRuntimeConfig().public.apiBase, namespace, name), {
        headers: {
            Authorization: "Bearer " + requireToken()
        }
    })
    .then(() => {
        onSuccess();
    })
    .catch();
}

function getParams(namespace: string | undefined)
{
    if(namespace != undefined)
    {
        return {
            namespace: namespace
        }
    }
    return undefined;
}