import {
  AddMaterialBindListParams,
  BaseListResult,
  BaseResult,
  EditMaterialBindListParams,
  GetMaterialBindrListParams,
  MaterialBindListData,
  UserListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/userMaterial';

/** 获取绑定列表 */
export function getMaterialBindList(
  data: GetMaterialBindrListParams,
  signal?: AbortSignal,
): BaseListResult<MaterialBindListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getUserMaterial`,
    data,
    signal,
  });
}

/** 获取绑定列表 */
export function getMaterialBindInfo(
  id: string,
): BaseListResult<MaterialBindListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getUserMaterial`,
    data: {page: '1', limit: '1', id},
  });
}

/** 新增绑定 */
export function addMaterialBind(data: AddMaterialBindListParams): BaseResult {
  return request({
    method: 'POST',
    url: `${BASE_URL}/addUserMaterial`,
    data,
  });
}

/** 修改绑定 */
export function editMaterialBind(data: EditMaterialBindListParams): BaseResult {
  return request({
    method: 'POST',
    url: `${BASE_URL}/updateUserMaterial`,
    data,
  });
}

/** 删除绑定 */
export function delMaterialBind(id: string): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delUserMaterial`,
    data: {id},
  });
}

/** 查询所有用户信息 */
export function getAllUser(signal?: AbortSignal): BaseResult<UserListData[]> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getUser`,
    signal,
  });
}

/** 导出绑定信息 */
export function exportUserBind(data: GetMaterialBindrListParams): any {
  return request({
    method: 'GET',
    url: `${BASE_URL}/Export`,
    data,
    skipError: true,
  });
}
