import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";
import { Grade } from "../grades";
import { PositionResult } from "../positions";

export type GradeLogInfo = {
    id: number,
    staffId: number,
    staffName: String,
    staffCode: String,
    grade: Grade,
    from: number[],
    to?: number[],
}

export type PositionLogInfo = {
    id: number,
    staffId: number,
    staffName: String,
    staffCode: String,
    position: PositionResult,
    from: number[],
    to?: number[],
}

type team = {
    id: number;
    description: string;
    name: string;
    code: string;
    teamLead?: number
}

export type TeamLogInfo = {
    id: number,
    staffId: number,
    staffName: string,
    staffCode: string,
    team: team,
    from: number[],
    to?: number[],
}

export const fetchGradesLog = cache(async (staffId: number) => {
    return serverFetchJson<GradeLogInfo[]>(`${BASE_API_URL}/gradeLog/${staffId}`, {
      next: { tags: ["grades"] },
    });
  });
  

export const fetchPositionLog = cache(async (staffId: number) => {
    return serverFetchJson<PositionLogInfo[]>(`${BASE_API_URL}/positionLog/${staffId}`, {
      next: { tags: ["position"] },
    });
  });

export const fetchTeamLog = cache(async (staffId: number) => {
    return serverFetchJson<TeamLogInfo[]>(`${BASE_API_URL}/teamLog/${staffId}`, {
      next: { tags: ["team"] },
    });
  });
  