import request from './request'

export interface TaskItem {
  id: number
  name: string
  project_id: number
  project_name?: string
  status: string
  deadline?: string
  created_at: string
}

export interface TaskResultItem {
  result_id: number
  column_id: number
  column_name: string
  data_type?: string
  comment?: string
  table_name?: string
  database_name?: string
  source_name?: string
  category_id?: number
  category_name?: string
  level_id?: number
  level_name?: string
  level_color?: string
  source: string
  confidence: number
  status: string
}

export function getMyTasks(params?: { status?: string }) {
  return request.get('/tasks/my-tasks', { params })
}

export function getTaskItems(taskId: number, params?: { keyword?: string }) {
  return request.get(`/tasks/my-tasks/${taskId}/items`, { params })
}

export function startTask(taskId: number) {
  return request.post(`/tasks/my-tasks/${taskId}/start`)
}

export function completeTask(taskId: number) {
  return request.post(`/tasks/my-tasks/${taskId}/complete`)
}

export function labelResult(resultId: number, data: { category_id: number; level_id: number }) {
  return request.post(`/tasks/results/${resultId}/label`, null, { params: data })
}

export function createTask(projectId: number, data: { name: string; assignee_id: number; target_type?: string }) {
  return request.post(`/tasks/projects/${projectId}/create-task`, null, { params: data })
}
