import request from '@/utils/request';

export async function listOrganizations(params) {
  const res = await request.get('organization/manage', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function addOrganization(data) {
  const res = await request.post('/organization/manage', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function updateOrganization(data) {
  const res = await request.put('/organization/manage', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function removeOrganization(id) {
  const res = await request.delete('/organization/manage', {
    data: { id }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
