import request from '@/utils/request';

// 创建用户组
export async function createUserGroup(data) {
  const res = await request({
    url: '/bpm/user-group/create',
    method: 'post',
    data: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 更新用户组
export async function updateUserGroup(data) {
  const res = await request({
    url: '/bpm/user-group/update',
    method: 'put',
    data: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除用户组
export async function deleteUserGroup(id) {
  const res = await request({
    url: '/bpm/user-group/delete?id=' + id,
    method: 'delete'
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获得用户组
export async function getUserGroup(id) {
  const res = await request({
    url: '/bpm/user-group/get?id=' + id,
    method: 'get'
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 获得用户组分页
export async function getUserGroupPage(query) {
  const res = await request({
    url: '/bpm/user-group/page',
    method: 'get',
    params: query
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取用户组精简信息列表
export async function listSimpleUserGroups() {
  const res = await request({
    url: '/bpm/user-group/list-all-simple',
    method: 'get'
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}