import request from '@/utils/request'
import {
  add,
  del,
  update,
  send
} from '@/api/base'

export function getCredits (query) {
  const { pageNum: pageIndex, pageSize, ...params } = query
  return request({
    url: '/minio-data/ai/credit/listByPage',
    method: 'GET',
    params: {
      admin: 1,
      pageIndex, pageSize,
      ...params
    }
  })
}

export function getTenantCredits (query) {
  const { pageNum: pageIndex, pageSize, ...params } = query
  return request({
    url: '/minio-data/ai/credit/listByPage',
    method: 'GET',
    params: {
      admin: 0,
      pageIndex, pageSize,
      ...params
    }
  })
}

export function addCredit (data) {
  return add({
    url: '/minio-data/ai/credit/deposit',
    method: 'POST',
    data
  })
}

export function deleteCredit ({ id, auditType }) {
  return del({
    url: `/minio-data/ai/credit/${id}`,
    method: 'DELETE'
  }, ['库存', '图片库存', '视频库存'][auditType])
}

export function getCreditConfig (tenant) {
  return send({
    url: '/minio-data/ai/credit/warn/config',
    method: 'GET',
    params: { tenant }
  })
}

export function addCreditConfig (threshold, tenant) {
  return add({
    url: '/minio-data/ai/credit/warn/config',
    method: 'POST',
    data: { tenant, threshold }
  })
}

export function updateCreditConfig (threshold, tenant) {
  return update({
    url: '/minio-data/ai/credit/warn/config',
    method: 'PUT',
    data: { tenant, threshold }
  })
}
