import { requestClient } from '#/api/request';

/**
 * 系统配置接口
 */
export interface SystemConfig {
  id?: number;
  site_id?: number;
  config_key: string;
  value: string;
  status?: number;
  create_time?: string;
  update_time?: string;
  addon?: string;
}

/**
 * 系统信息接口
 */
export interface SystemInfo {
  os: string;
  server: string;
  php_version: string;
  mysql_version: string;
  redis_version: string;
  node_version: string;
  memory_usage: string;
  disk_usage: string;
}

/**
 * 基本信息配置
 */
export interface BasicConfig {
  site_name: string;
  site_title: string;
  site_description: string;
  site_keywords: string;
  site_icp: string;
  site_copyright: string;
}

/**
 * 系统配置
 */
export interface ConfigSettings {
  site_status: string;
  site_close_reason?: string;
  timezone: string;
  default_language: string;
  page_size: number;
  cache_enabled: boolean;
  debug_enabled: boolean;
}

/**
 * 获取系统配置
 * @param type 配置类型
 */
export async function getSystemConfigApi(type: 'basic' | 'config'): Promise<any> {
  return requestClient.get(`/api/system/config/${type}`);
}

/**
 * 更新系统配置
 * @param type 配置类型
 * @param data 配置数据
 */
export async function updateSystemConfigApi(
  type: 'basic' | 'config',
  data: BasicConfig | ConfigSettings,
): Promise<void> {
  return requestClient.put(`/api/system/config/${type}`, data);
}

/**
 * 获取系统信息
 */
export async function getSystemInfoApi(): Promise<SystemInfo> {
  return requestClient.get('/api/system/info');
}

/**
 * 导出系统信息
 */
export async function exportSystemInfoApi(): Promise<void> {
  return requestClient.get('/api/system/info/export', {
    responseType: 'blob',
  });
}

/**
 * 重置系统配置
 * @param type 配置类型
 */
export async function resetSystemConfigApi(type: 'basic' | 'config'): Promise<void> {
  return requestClient.post(`/api/system/config/${type}/reset`);
}

/**
 * 清除系统缓存
 */
export async function clearSystemCacheApi(): Promise<void> {
  return requestClient.post('/api/system/cache/clear');
}