import {
  IAddCommissionResponse,
  IChangeCommissionResponse,
  IChangeCommissionStatusResponse,
  ICommission,
  IDelCommissionResponse,
  IGetCommissionByPriceResponse
} from "@/api/commission/types/commission"
import { request } from "@/utils/service"
import { AxiosResponseData, IPageResponseData } from "@/api/types/requests"

export function addCommissionApi(commission: ICommission) {
  return request<AxiosResponseData<IAddCommissionResponse>>({
    url: "/commission/addCommission",
    method: "POST",
    data: commission,
    withCredentials: true
  })
}
export function changeCommissionApi(commission: ICommission) {
  return request<AxiosResponseData<IChangeCommissionResponse>>({
    url: "/commission/changeCommission",
    method: "POST",
    data: commission,
    withCredentials: true
  })
}
export function delCommissionApi(id: number) {
  return request<AxiosResponseData<IDelCommissionResponse>>({
    url: "/commission/delCommission",
    method: "GET",
    params: {
      id: id
    },
    withCredentials: true
  })
}
export function getCommissionsApi(page: number) {
  return request<AxiosResponseData<IPageResponseData<ICommission>>>({
    url: "/commission/getCommission",
    method: "GET",
    params: {
      page: page,
      num: 10
    },
    withCredentials: true
  })
}
export function getCommissionsByPriceApi(shopId: number, range: number) {
  return request<AxiosResponseData<IGetCommissionByPriceResponse>>({
    url: "/commission/getCommissionByPrice",
    method: "GET",
    params: {
      shopId: shopId,
      range: range
    },
    withCredentials: true
  })
}

export function changeCommissionStatusApi(commission: ICommission) {
  return request<AxiosResponseData<IChangeCommissionStatusResponse>>({
    url: "/commission/changeCommissionStatus",
    method: "GET",
    params: {
      commissionId: commission.id,
      status: !commission.status
    },
    withCredentials: true
  })
}
