import request from '@/utils/request'

// 将大写字段转换为小写驼峰格式
function convertToCamelCase(data) {
  if (!data || !Array.isArray(data)) return data
  return data.map(item => {
    const converted = {}
    for (const key in item) {
      if (item.hasOwnProperty(key)) {
        // 将大写下划线格式转换为小写驼峰格式
        const camelKey = key.toLowerCase().replace(/_([a-z])/g, (match, letter) => letter.toUpperCase())
        converted[camelKey] = item[key]
      }
    }
    return converted
  })
}

// ==================== 制度规则 ====================
export function listRule(adCode, ruleType) {
  return request({ url: '/hzz/rule/list', method: 'get', params: { adCode, ruleType } })
}

// ==================== 制度文件 ====================
export function listFile(query) {
  return request({ url: '/hzz/rule/file/list', method: 'get', params: query })
}
export function addFile(data) {
  return request({ url: '/hzz/rule/file', method: 'post', data })
}
export function updateFile(data) {
  return request({ url: '/hzz/rule/file', method: 'put', data })
}
export function delFile(guid) {
  return request({ url: '/hzz/rule/file/' + guid, method: 'delete' })
}

// ==================== 工作动态 ====================
export function listArticle(query) {
  return request({ url: '/hzz/rule/article/list', method: 'get', params: query })
}
export function getArticleTop5(type) {
  return request({ url: '/hzz/rule/article/top5', method: 'get', params: { type } })
}
export function addArticle(data) {
  return request({ url: '/hzz/rule/article', method: 'post', data })
}
export function updateArticle(data) {
  return request({ url: '/hzz/rule/article', method: 'put', data })
}
export function delArticle(guid) {
  return request({ url: '/hzz/rule/article/' + guid, method: 'delete' })
}
