// Revit API服务 - 完全复制creo结构
// 严格遵循开发规范：核心需求优先，杜绝过度工程

import apiClient from './apiClient'
import { buildApiUrl } from '@/config/cad'

// 重复使用的常量
const SOFTWARE_TYPE = "revit"

// Revit API服务类
class RevitApiService {
  constructor() {
    this.softwareName = 'revit'
  }

  /**
   * 测试Revit连接
   * @returns {Promise<{success: boolean, data?: any, error?: string}>}
   */
  async testConnection() {
    // 构建连接测试URL
    const url = buildApiUrl(this.softwareName, 'connect')

    // 调用统一API客户端（错误处理和通知由apiClient统一管理）
    return await apiClient.get(url, {
      operationContext: {
        software: 'Revit',
        operation: '连接测试'
      }
    })
  }

  /**
   * 获取当前模型总览
   * @returns {Promise<{success: boolean, data?: any, error?: string}>}
   */
  async getCurrentModel() {
    const url = buildApiUrl(this.softwareName, 'overview')

    return await apiClient.get(url, {
      operationContext: {
        software: 'Revit',
        operation: '获取当前模型'
      }
    })
  }

  /**
   * 开始薄壳化分析
   * @returns {Promise<{success: boolean, data?: any, error?: string}>}
   */
  async startShellAnalysis() {
    const url = buildApiUrl(this.softwareName, 'shellAnalysis')

    return await apiClient.post(url, {
      "software_type": SOFTWARE_TYPE,
      "mode": "Standard"
    }, {
      operationContext: {
        software: 'Revit',
        operation: '薄壳化分析'
      }
    })
  }

  /**
   * 导出IFC文件
   * @param {Object} exportOptions - 导出选项
   * @returns {Promise<{success: boolean, data?: any, error?: string}>}
   */
  async exportIFC(exportOptions) {
    const url = buildApiUrl(this.softwareName, 'exportIfc')

    return await apiClient.post(url, exportOptions, {
      operationContext: {
        software: 'Revit',
        operation: 'IFC导出'
      }
    })
  }
}

// 导出单例实例
export const revitApi = new RevitApiService()

// 默认导出
export default revitApi