/**
 * 安全测试 ERP 配置 API 封装
 *
 * @author czj
 * @date 2026-08-13
 */

import request from '@/utils/request'

export const securityErpApi = {
  /**
   * 获取 ERP 配置
   * 优先从数据库读取，无记录时回退到环境变量默认值
   */
  async getConfig(): Promise<{
    api_key: string
    base_url: string
    developtesting_id: number
    type_id: number
    image_url_prefix: string
  }> {
    const response = await request.get('/api/security/erp-config')
    return response as any
  },

  /**
   * 更新 ERP 配置
   * 持久化到数据库，同时更新运行时环境变量
   */
  async updateConfig(config: {
    api_key?: string
    base_url?: string
    developtesting_id?: number
    type_id?: number
    image_url_prefix?: string
  }): Promise<any> {
    const response = await request.put('/api/security/erp-config', config)
    return response as any
  }
}