"use server";
import { cache } from "react";
import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";

export type ProjectExpensesResult = {
    id: number
    expenseNo?: string
    projectCode: string
    projectName: string
    teamId: number
    teamCode: string
    teamName: string
    amount: number
    issueDate: number[]
    receiptDate: number[]
    remarks?: string
    team: string
}

export type ProjectExpensesResultFormatted = Omit<ProjectExpensesResult, 'issueDate' | 'receiptDate'> & {
  issueDate: string;
  receiptDate: string;
};

export const preloadProjectExpenses = () => {
  fetchProjectExpenses()
  };
  
export const fetchProjectExpenses = cache(async () => {
    return serverFetchJson<ProjectExpensesResult[]>(`${BASE_API_URL}/project-expense`, {
      next: { tags: ["projectExpenses"] },
    });
  });