import { DailyStats } from "@/types/DailyStats";
import { LineChartArr, LineChartItem } from "@/types/LineChartStats";

const lineChartArr = (dailyStatsArr: DailyStats): LineChartArr => {
  const lineChartArr = [] as LineChartArr;

  if (dailyStatsArr.length) {
    dailyStatsArr.forEach((item) => {
      const { linksDeleted, commandResponses, timesTriggered, createdAt } =
        item;

      const day = new Date(Number(createdAt)).getDate();

      const lineChartItem: LineChartItem = {
        day,
        "Links Deleted": linksDeleted,
        "Command Responses": commandResponses,
        "Times Triggered": timesTriggered
      };

      lineChartArr.push(lineChartItem);
    });
  }

  return lineChartArr;
};

export default lineChartArr;
