import { ipcMain } from 'electron'

import { listModels, testModelConnection } from '../services/modelService'
import type {
  ListModelsRequest,
  ModelConfig,
  ModelListResponse,
  TestModelConnectionResponse
} from '../types/model'

export function registerModelIpc(): void {
  ipcMain.handle(
    'models:list',
    async (_, payload: ListModelsRequest): Promise<ModelListResponse> => {
      return listModels(payload)
    }
  )

  ipcMain.handle(
    'models:test-connection',
    async (_, payload: ModelConfig): Promise<TestModelConnectionResponse> => {
      return testModelConnection(payload)
    }
  )
}
