import { campaignTemplateService } from "services";
import { useQuery } from "@tanstack/react-query";
import { Maybe } from "types/utilities";

export const useEmailCampaignTemplate = (campaignTemplateId: Maybe<string>) => {
  return useQuery({
    queryKey: ["campaigns", campaignTemplateId, "template"],
    queryFn: () => {
      if (!campaignTemplateId) return null;

      const template =
        campaignTemplateService.getCampaignTemplate(campaignTemplateId);
      return template || null;
    },
    enabled: Boolean(campaignTemplateId),
  });
};
