import api from "./api.js";
import { unwrapList } from "./http.js";
import { normalizeLocationRow } from "../utils/permitFilters.js";

export const MASTER_TABLES = [
  "job_title",
  "roles",
  "account_status",
  "departments",
  "country",
  "city",
  "tickets_status",
  "tickets_type",
  "ptw_form_type",
  "ptw_job_type",
  "ptw_question_type",
  "ptw_permit_status"
];

export async function listMaster(table, query = {}) {
  const res = await api.get(`/${table}`, { params: query });
  return unwrapList(res);
}

export async function listLocations(query = {}) {
  const res = await api.get("/locations", { params: query });
  return unwrapList(res)
    .map(normalizeLocationRow)
    .filter(Boolean);
}
