import api from './index'

export interface ForumPost {
  id: string
  user_id: string
  title: string
  content: string
  category?: string
  is_executed: boolean
  execution_result?: string
  reply_count: number
  created_at: string
}

export interface ForumReply {
  id: string
  post_id: string
  user_id?: string
  agent_id?: string
  content: string
  is_ai_reply: boolean
  created_at: string
}

export const forumApi = {
  listPosts() {
    return api.get<ForumPost[]>('/api/forum/posts')
  },

  createPost(data: { title: string; content: string; category?: string }) {
    return api.post<ForumPost>('/api/forum/posts', data)
  },

  getPost(id: string) {
    return api.get<ForumPost>(`/api/forum/posts/${id}`)
  },

  deletePost(id: string) {
    return api.delete(`/api/forum/posts/${id}`)
  },

  listReplies(postId: string) {
    return api.get<ForumReply[]>(`/api/forum/posts/${postId}/replies`)
  },

  createReply(postId: string, content: string) {
    return api.post<ForumReply>(`/api/forum/posts/${postId}/replies`, { content })
  },
}
