"server only"

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

export interface EscalationResult {
    id: number;
    submitter?: string;
    handler?: string;
    handlerDepartment?: string;
    handlerName?: string;
    handlerTitle?: string;
    polId?: number;
    poId?: number;
    reason?: string;
    handlerId?: number;
    status: string;
    recordDate: string;
    itemName?: string;
    demandQty?: number;
    acceptedQty?: number;
    purchaseUomCode?: string;
    purchaseUomDesc?: string;
    stockUomCode?: string;
    stockUomDesc?: string;
    stockInLineId?: number;
    stockOutLineId?: number;
    qcFailCount?: number;
    qcTotalCount?: number;
    poCode?: string;
    jobOrderId?: number;
    jobOrderCode?: string;
    itemCode?: string;
    dnDate?: number[];
    dnNo?: string;
}

export const fetchEscalationLogsByUser = cache(async() => {
    return serverFetchJson<EscalationResult[]>(`${BASE_API_URL}/escalationLog/user`, 
    {
        method: "GET",
        headers: { "Content-Type": "application/json" },
        next: {
            tags: ["escalationLogs"],
        },
    },
    );
});