import { AxiosResponseData, IPageResponseData, pageSize } from "@/api/types/requests"
import { request } from "@/utils/service"
import { AuthRoles, RolePermission } from "@/api/roles/types/Roles"
import { PermissionsIdName } from "@/api/permission/type/permission"
type ApiType = AuthRoles
const apiName = "authRoles"
const upperName = "AuthRoles"
export function add(data: ApiType) {
  return request<AxiosResponseData<boolean>>({
    url: "/" + apiName + "/add" + upperName,
    method: "POST",
    data: data,
    withCredentials: true
  })
}
export function change(newData: ApiType) {
  return request<AxiosResponseData<string>>({
    url: "/" + apiName + "/change" + upperName,
    method: "POST",
    data: newData,
    withCredentials: true
  })
}
export function delete_(id: number) {
  return request<AxiosResponseData<boolean>>({
    url: "/" + apiName + "/del" + upperName,
    method: "GET",
    params: {
      id: id
    },
    withCredentials: true
  })
}
export function get(page: number) {
  return request<AxiosResponseData<IPageResponseData<ApiType>>>({
    url: "/" + apiName + "/get" + upperName,
    method: "GET",
    params: {
      page: page,
      num: pageSize
    },
    withCredentials: true
  })
}
export function status(id: number, status: boolean) {
  return request<AxiosResponseData<string>>({
    url: "/" + apiName + "/change" + upperName + "Stats",
    method: "GET",
    params: {
      authPermissionId: id,
      status: status
    },
    withCredentials: true
  })
}
export function getAuthPermissionId(roleId: number) {
  return request<AxiosResponseData<RolePermission[]>>({
    url: "/" + apiName + "/getAuthPermissionId",
    method: "GET",
    params: {
      roleId: roleId
    },
    withCredentials: true
  })
}
export function getAllPermissions() {
  return request<AxiosResponseData<PermissionsIdName[]>>({
    url: "/authPermissions/getAuthPermissionsId",
    method: "GET",
    withCredentials: true
  })
}
