import { useQuery } from "@tanstack/react-query";

const QUALITEER_URL = "https://qualiteer.elijahparker3.repl.co/api";

const useMock = true;

const asMock = (data) => ({ data });

const fetchApi = (subPath) => async () =>
  fetch(`${QUALITEER_URL}${subPath}`).then((res) => res.json());

export const useCatalogTests = () =>
  useMock ? asMock([]) : useQuery(["catalogTests"], fetchApi("/catalog/tests"));

export const usePipelineMappings = () =>
  useMock
    ? asMock([
        ["primary", "secondary1", "tertiary1"],
        ["primary", "secondary1", "tertiary2"],
        ["primary", "secondary2", "tertiary3"],
      ])
    : useQuery(["pipelineMappings"], fetchApi("/catalog/pipeline-mappings"));

export const useSilencedAlerts = () =>
  useMock ? asMock([]) : useQuery(["silenced"], fetchApi("/alerting/silenced"));

export const useCurrentlyFailing = () =>
  useMock ? asMock([]) : useQuery(["failing"], fetchApi("/results/failing"));
