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

export namespace SettingApi {
  /** 系统设置 */
  export interface SettingInfo {
    site_name?: string;
    site_desc?: string;
    site_icp?: string;
    site_banners?: string; // JSON字符串
    default_avatar?: string;
    upload_allowed_ext?: string;
    upload_max_size?: string;
    upload_path?: string;
    upload_image_size?: string;
    upload_image_ext?: string;
    mail_host?: string;
    mail_port?: string;
    mail_username?: string;
    mail_password?: string;
    wxapp_appid?: string;
    wxapp_secret?: string;
    wxapp_name?: string;
    wxapp_original?: string;
    [key: string]: any;
  }

  /** 保存系统设置参数 */
  export interface SaveParams extends SettingInfo {
    [key: string]: any;
  }
}

/**
 * 获取系统设置（仅超级管理员）
 * GET /api/admin/setting/get
 */
export async function getSettingApi() {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/setting/get', {
    responseReturn: 'body',
  });
}

/**
 * 保存系统设置（仅超级管理员）
 * POST /api/admin/setting/save
 */
export async function saveSettingApi(data: SettingApi.SaveParams) {
  return requestClient.post('/api/admin/setting/save', data);
}

/**
 * 上传图片（仅超级管理员）
 * POST /api/admin/setting/upload
 */
export async function uploadSettingImageApi(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.post<any>('/api/admin/setting/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    responseReturn: 'body',
  });
}

