import request from '@/utils/request'

export function listWarningItems(params) {
  return request({
    url: '/warning/item/list',
    method: 'get',
    params
  })
}

export function addWarningItem(data) {
  return request({
    url: '/warning/item/add',
    method: 'post',
    data
  })
}

export function updateWarningItem(data) {
  return request({
    url: '/warning/item/update',
    method: 'put',
    data
  })
}

export function updateWarningItemStatus(itemId, status) {
  return request({
    url: '/warning/item/status',
    method: 'put',
    params: { itemId, status }
  })
}

export function getWarningItemDetail(itemId) {
  return request({
    url: `/warning/item/detail/${itemId}`,
    method: 'get'
  })
}

export function getWarningItemByCode(itemCode) {
  return request({
    url: `/warning/item/detail/code/${encodeURIComponent(itemCode)}`,
    method: 'get'
  })
}

export function generateWarningItemCode(warningType, warningLevel) {
  return request({
    url: '/warning/item/code/generate',
    method: 'get',
    params: { warningType, warningLevel }
  })
}

export function listWarningReasons(params) {
  return request({
    url: '/warning/reason/list',
    method: 'get',
    params
  })
}

export function listReasonsByTypeAndLevel(warningType, warningLevel) {
  return request({
    url: '/warning/reason/query',
    method: 'get',
    params: { warningType, warningLevel }
  })
}

export function addWarningReason(data) {
  return request({
    url: '/warning/reason/add',
    method: 'post',
    data
  })
}

export function updateWarningReason(data) {
  return request({
    url: '/warning/reason/update',
    method: 'put',
    data
  })
}

export function updateWarningReasonStatus(reasonId, status) {
  return request({
    url: '/warning/reason/status',
    method: 'put',
    params: { reasonId, status }
  })
}

export function getWarningReasonDetail(reasonId) {
  return request({
    url: `/warning/reason/detail/${reasonId}`,
    method: 'get'
  })
}
