import { useConfig } from "../../ConfigProvider";
import { useMutation } from "@tanstack/react-query";
import { fetch_ } from "../request-utils";

export const useCreateApiKey = () => {
    const config = useConfig();
    return useMutation({
        mutationFn: async ({ name, roles }) => {
            const response = await fetch_(`${config.BACKEND_HOST}/api/apikey/`, {
                method: "POST",
                body: JSON.stringify({ name, roles }),
            });
            console.log("response", response);
            return response;
        },
        cacheTime: 0,
    });
};

export const useRevokeApiKey = () => {
    const config = useConfig();
    return useMutation({
        mutationFn: async (apiKey) => {
            const response = await fetch_(`${config.BACKEND_HOST}/api/apikey/revoke`, {
                method: "POST",
                body: JSON.stringify({ apiKey }),
            });
            return response;
        },
        cacheTime: 0,
    });
}; 