import { apiFetch } from "./http";
import type { SalaryProfileRecord, SalaryProfileRequest } from "./types";

export function listSalaryProfiles(keyword = ""): Promise<SalaryProfileRecord[]> {
  const search = new URLSearchParams();
  if (keyword.trim()) {
    search.set("keyword", keyword.trim());
  }
  const query = search.toString();
  return apiFetch<SalaryProfileRecord[]>(`/api/salary-profiles${query ? `?${query}` : ""}`);
}

export function saveSalaryProfile(payload: SalaryProfileRequest): Promise<SalaryProfileRecord> {
  return apiFetch<SalaryProfileRecord>(`/api/salary-profiles/${payload.employee_id}`, {
    method: "PUT",
    body: JSON.stringify(payload),
  });
}
