import { request } from '../request';

// 定义 API URL 常量
const BASE_URL = 'http://localhost:58926/api';

// 声明接口 URL 变量
const GET_ROLE_LIST_URL = `${BASE_URL}/System/GetRoleList`;
const GET_ALLROLE_LIST_URL = `${BASE_URL}/System/GetAllRoleList`;
const GET_ADDROLE_URL = `${BASE_URL}/System/AddRoleInfo`;
const GET_UPDATEROLE_URL = `${BASE_URL}/System/UpDateRole`;
const GET_GETUSERLIST = `${BASE_URL}/System/GetUserInfoList`;
const GET_DELETEUSER = `${BASE_URL}/System/DeleteUser`;
const GET_DELETEROLE = `${BASE_URL}/System/DeleteRole`;
const GET_ADDUSERINFO = `${BASE_URL}/System/AddUserInfo`;
const GET_UPDATEUSERINFO = `${BASE_URL}/System/UpDateUser`;
const GET_CODELIST = `${BASE_URL}/System/GetCodeList`;
const GET_ALLCODELIST = `${BASE_URL}/System/GetAllCodeList`;

/** get code list */
export function fetchGetCodeList(params?: Api.SystemManage.CodesSearchParams) {
  return request<Api.SystemManage.CodesList>({
    url: GET_CODELIST,
    method: 'post',
    data: params
  });
}
export function fetchGetCodeList2(params?: Api.SystemManage.CodesSearchParams) {
  return request<Api.SystemManage.CodesListData2>({
    url: GET_CODELIST,
    method: 'post',
    data: params
  });
}
/** get codeall list */
export function fetchGetCodeALLList() {
  return request<Api.SystemManage.CodesListData>({
    url: GET_ALLCODELIST,
    method: 'post'
  });
}

/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: GET_ROLE_LIST_URL,
    method: 'post',
    data: params
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.RoleListData>({
    url: GET_ALLROLE_LIST_URL,
    method: 'post'
  });
}

/** 新增角色 */
export function AddRoleInfo(data: object) {
  return request<Api.SystemManage.UserDelInfo>({
    url: GET_ADDROLE_URL,
    method: 'post',
    data: {
      data
    }
  });
}

/** 修改角色 */
export function UpDateRoleInfo(data: object) {
  return request<Api.SystemManage.UserInfoData>({
    url: GET_UPDATEROLE_URL,
    method: 'post',
    data: {
      data
    }
  });
}
/** 删除角色 */
export async function DeleteRole(idList: number[]) {
  return request<Api.SystemManage.UserInfo>({
    url: GET_DELETEROLE,
    method: 'post',
    data: {
      idList
    }
  });
}

// /** get user list */
// export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
//   return request<Api.SystemManage.UserList>({
//     url: '/systemManage/getUserList',
//     method: 'get',
//     params
//   });
// }

/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: GET_GETUSERLIST,
    // url: '/systemManage/getUserList',
    method: 'post',
    data: params
  });

  // return userlist.data;
}

/** 删除用户 */
export async function DeleteUser(idList: number[]) {
  return request<Api.SystemManage.UserInfo>({
    url: GET_DELETEUSER,
    method: 'post',
    data: {
      idList
    }
  });
}

/** 新增用户 */
export function AddUserInfo(data: object) {
  return request<Api.SystemManage.UserDelInfo>({
    url: GET_ADDUSERINFO,
    method: 'post',
    data: {
      data
    }
  });
}

/** 修改用户 */
export function UpDateUserInfo(data: object) {
  return request<Api.SystemManage.UserInfoData>({
    url: GET_UPDATEUSERINFO,
    method: 'post',
    data: {
      data
    }
  });
}

/** get menu list */
export function fetchGetMenuList() {
  return request<Api.SystemManage.MenuList>({
    url: '/systemManage/getMenuList/v2',
    method: 'get'
  });
}

/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/systemManage/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/systemManage/getMenuTree',
    method: 'get'
  });
}
