import { httpApp } from "@/plugins/axiosIndex";
import { pickBy } from "lodash-es";
import { object2QueryString } from "@/utils/utils";

export function searchOrgs({
  code = "",
  name = "",
  enable = "",
  pageNumber = 1,
  pageSize = 10,
}) {
  const data = pickBy(
    { code, name, enable, pageNumber, pageSize },
    (v) => v !== ""
  );
  return httpApp.post("/api/admin/org/query?" + object2QueryString(data));
}

export function toggleEnableOrg({ id, enable }) {
  return httpApp.post("/api/admin/org/enable", { id, enable });
}

export function searchOrg(id) {
  return httpApp.post("/api/admin/sys/org/query?" + object2QueryString({ id }));
}

export function saveOrg({
  id = "",
  name = "",
  code = "",
  contactName = "",
  contactPhone = "",
  logo = null,
  enableSimulate = 0,
  enableMonitorRecord = 0,
  enableLiveness = 0,
  enable = 0,
}) {
  const data = pickBy(
    {
      id,
      name,
      code,
      contactName,
      contactPhone,
      // logo,
      enableSimulate,
      enableMonitorRecord,
      enableLiveness,
      enable,
    },
    (v) => v !== ""
  );
  return httpApp.post("/api/admin/org/save", { ...data, logo });
}
