import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

type deptResult = {
  data: Array<any>;
};

/** 部门列表查询 */
export const getDeptList = (params?: object) => {
  return http.request<deptResult>("get", baseUrlApi("departments/"), {
    params
  });
};

type deptStatus = {
  success: boolean;
  msg: any;
};

/** 新增部门 */
export const addDept = (data?: object) => {
  return http.request<deptStatus>("post", baseUrlApi("departments/"), {
    data
  });
};

/** 更新部门 */
export const updateDept = (data?: object | any) => {
  return http.request<deptStatus>(
    "put",
    baseUrlApi(`departments/${data.id}/`),
    {
      data
    }
  );
};

/** 删除部门 */
export const deleteDept = (data?: object | any) => {
  return http.request<deptStatus>(
    "delete",
    baseUrlApi(`departments/${data}/`),
    {
      data
    }
  );
};

type userList = {
  count: number;
  next: any;
  previous: any;
  results?: Array<any>;
};

/** 用户列表查询 */
export const getUserList = (params?: object) => {
  return http.request<userList>("get", baseUrlApi("user/"), {
    params
  });
};

type userStatus = {
  success: boolean;
  msg: any;
};
/** 新增用户 */
export const addUser = (data?: object) => {
  return http.request<userStatus>("post", baseUrlApi("user/"), { data });
};

/** 更新用户 */
export const updateUser = (data?: object | any) => {
  return http.request<userStatus>("put", baseUrlApi(`user/${data.id}/`), {
    data
  });
};

/** 删除用户 */
export const deleteUser = (data?: object | any) => {
  return http.request<userStatus>("delete", baseUrlApi(`user/${data}/`), {
    data
  });
};
