import { http as request } from './http'

export const chatApi = {
  // Create Conversation
  async createConversation(title) {
    const { data } = await request.post('api/ai/conversations', { title })
    return data.data
  },
  // Get List
  async getConversations() {
    const { data } = await request.get('api/ai/conversations')
    return data.data
  },
  // Delete
  async deleteConversation(id) {
    const { data } = await request.delete(`api/ai/conversations/${id}`)
    return data.data
  },
  // Update Title
  async updateConversation(id, title) {
    const { data } = await request.put(`api/ai/conversations/${id}`, { title })
    return data.data
  },
  // Search
  async searchConversations(query) {
    const { data } = await request.get('api/ai/conversations/search', { params: { query } })
    return data.data
  },
  // Save Message
  async saveMessage(conversationId, role, content) {
    const { data } = await request.post(`api/ai/conversations/${conversationId}/messages`, { role, content })
    return data.data
  },
  // Get Messages
  async getMessages(conversationId) {
    const { data } = await request.get(`api/ai/conversations/${conversationId}/messages`)
    return data.data
  }
}
