import axios from '@/network/axios';
import { useQuery } from '@tanstack/react-query';

export type ApprovedTemplate = {
  id: number;
  name: string | null;
  title: string | null;
  title_ar: string | null;
  title_en: string | null;
  body_text: string | null;
  status: string | null;
  published: number | boolean;
  body_vars_count: number;
  body_vars_defaults: string[] | null;
  language_code: string | null;
  category: string | null;
};

/**
 * Only templates Morasalaty has approved + published (and not archived) are
 * returned by the backend — these are the only ones allowed for a bulk blast.
 */
const getApprovedTemplates = async (): Promise<ApprovedTemplate[]> => {
  const { data } = await axios.get<{ data: { templates: ApprovedTemplate[] } }>(
    '/influencer-number/report/templates',
  );
  return data.data?.templates ?? [];
};

const useApprovedTemplates = () =>
  useQuery<ApprovedTemplate[]>({
    queryKey: ['morasalaty-approved-templates'],
    queryFn: getApprovedTemplates,
  });

export default useApprovedTemplates;
