import axios from "axios";
import config from "./config/config";
import logging from "./config/logging";
import { NAME_SPACE } from "./server";

export const rpt_052_000 = async (
  kode: string,
  date: string,
  target: string
) => {
  // etl/Tat/proses_etl/000/2021-06-12/0
  const url_tat =
    config.base_url + "etl/Tat/proses_etl/" + kode + "/" + date + "/" + target;
  logging.info(NAME_SPACE, "Info : " + url_tat);
  try {
    const resp = await axios.get(url_tat, {
      responseType: "arraybuffer",
    });
    const jresp = JSON.parse(resp.data.toString());
    return jresp;
  } catch (e) {
    if (axios.isAxiosError(e)) {
      logging.error(NAME_SPACE, e.response?.data.toString());
    } else if (e instanceof Error) {
      logging.error(NAME_SPACE, e.message);
    }
  }
};
