/**
 * 系统管理 API 接口
 *
 * @module api/system
 * @author czj
 * @date 2026-07-29
 */

import request from '@/utils/request'

/** 系统信息响应结构 */
export interface SystemInfo {
  app_name: string
  backend_version: string
  python_version: string
  platform: string
  os: string
  uptime_seconds: number
  uptime_text: string
  db_type: string
  db_size_mb: number
  total_modules: number
  total_cases: number
  debug: boolean
  playwright_headless: boolean
  frontend_version: string
}

/**
 * 系统管理 API 服务
 */
export const systemApi = {
  /**
   * 获取系统运行信息
   */
  async getInfo(): Promise<SystemInfo> {
    const response = await request.get('/api/system/info')
    return response as any
  },

  /**
   * 获取钉钉对接配置
   */
  async getDingTalkConfig(): Promise<{
    app_key: string
    app_secret: string
    agent_id: number
    target_url: string
  }> {
    const response = await request.get('/api/system/dingtalk-config')
    return response as any
  },

  /**
   * 更新钉钉对接配置
   */
  async updateDingTalkConfig(config: {
    app_key?: string
    app_secret?: string
    agent_id?: number
    target_url?: string
  }): Promise<any> {
    const response = await request.put('/api/system/dingtalk-config', config)
    return response as any
  },

  /**
   * 获取被测系统配置
   */
  async getSutConfig(): Promise<{ url: string; source: string }> {
    const response = await request.get('/api/system/sut-config')
    return response as any
  },

  /**
   * 更新被测系统配置
   */
  async updateSutConfig(url: string): Promise<{ url: string; source: string }> {
    const response = await request.put('/api/system/sut-config', { url })
    return response as any
  },
}
