import api from './index'

export interface Message {
  id: string
  role: 'user' | 'assistant'
  content: string
  model?: string
  tokens_used?: number
  created_at: string
}

export interface Conversation {
  id: string
  title?: string
  message_count: number
  created_at: string
  updated_at: string
}

export const conversationApi = {
  list() {
    return api.get<Conversation[]>('/api/conversations')
  },

  create(title?: string) {
    return api.post<Conversation>('/api/conversations', { title })
  },

  getMessages(conversationId: string) {
    return api.get<Message[]>(`/api/conversations/${conversationId}`)
  },

  delete(conversationId: string) {
    return api.delete(`/api/conversations/${conversationId}`)
  },

  chat(message: string, conversationId?: string, fileIds: string[] = []) {
    return api.post('/api/conversations/chat', {
      message,
      conversation_id: conversationId,
      file_ids: fileIds,
    })
  },
}
