// src/utils/http.js
import axios from '../config/service' // 基础配置

/**
 * 高级请求封装
 */
const http = {
  /**
   * GET 请求
   * @param {string} url 
   * @param {object} params 
   * @param {object} config 
   */
  get(url, params = {}, config = {}) {
    return axios.get(url, { params, ...config })
  },

  /**
   * POST 请求
   * @param {string} url 
   * @param {object} data 
   * @param {object} config 
   */
  post(url, data = {}, config = {}) {
    return axios.post(url, data, config)
  },

  /**
   * PUT 请求
   * @param {string} url 
   * @param {object} data 
   * @param {object} config 
   */
  put(url, data = {}, config = {}) {
    return axios.put(url, data, config)
  },

  /**
   * DELETE 请求
   * @param {string} url 
   * @param {object} params 
   * @param {object} config 
   */
  delete(url, params = {}, config = {}) {
    return axios.delete(url, { params, ...config })
  },

  /**
   * 文件上传
   * @param {string} url 
   * @param {FormData} formData 
   * @param {object} config 
   */
  upload(url, formData, config = {}) {
    return axios.post(url, formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
      ...config
    })
  }
}

export default http