import { LinksunBackend } from "@/services/api";

export interface FiltrosNotificacoes {
  data_inicio?: string;
  data_fim?: string;
  status?: string;
  acao?: string[];
  negocio_de?: string | number;
  negocio_ate?: string | number;
  urgencia?: string | number;
  tipo_agendamento?: string | number;
  cliente?: string | number;
}

export async function listarNotificacoes(
  id_usuario: any,
  filtros: FiltrosNotificacoes = {}
) {
  const nomeDaFuncao = "listarNotificacoes";
  const params = new URLSearchParams({
    action: nomeDaFuncao,
    class: "Notificacoes",
    id_usuario: String(id_usuario),
  });

  Object.entries(filtros).forEach(([chave, valor]) => {
    if (valor === undefined || valor === null || valor === "") return;
    if (Array.isArray(valor)) {
      if (valor.length) params.append(chave, valor.join(","));
    } else {
      params.append(chave, String(valor));
    }
  });

  const response = await LinksunBackend.get(`?${params.toString()}`).then(
    (res) => res.body
  );
  return response;
}

export async function listarAcoesNotificacoes() {
  const nomeDaFuncao = "listarAcoesNotificacoes";
  const response = await LinksunBackend.get(
    `?action=${nomeDaFuncao}&class=Notificacoes`
  ).then((res) => res.body);
  return response;
}

export async function listaAutomacao() {
  const nomeDaFuncao = "listaAutomacao";
  const response = await LinksunBackend.get(
    `?action=${nomeDaFuncao}&class=Notificacoes`
  ).then((res) => res.body);
  return response;
}
export async function listarNotificacoesAutomatizadas() {
  const nomeDaFuncao = "listarNotificacoesAutomatizadas";
  const response = await LinksunBackend.get(
    `?action=${nomeDaFuncao}&class=Notificacoes`
  ).then((res) => res.body);
  return response;
}

export async function gatilhosNotificacao($id_usuario: any) {
  const nomeDaFuncao = "gatilhosNotificacao";
  const response = await LinksunBackend.get(
    `?action=${nomeDaFuncao}&class=Notificacoes&id_usuario=${$id_usuario}`
  ).then((res) => res.body);
  return response;
}
