import api from './index'

export type TaskStatus = 'todo' | 'in_progress' | 'done' | 'cancelled'
export type TaskPriority = 'low' | 'medium' | 'high' | 'urgent'

export interface Task {
  id: string
  title: string
  description?: string
  status: TaskStatus
  priority: TaskPriority
  due_date?: string
  completed_at?: string
  tags?: string
  created_at: string
  updated_at: string
}

export const taskApi = {
  list(status?: TaskStatus) {
    return api.get<Task[]>('/api/tasks', { params: status ? { status } : {} })
  },

  create(data: { title: string; description?: string; priority?: TaskPriority; due_date?: string }) {
    return api.post<Task>('/api/tasks', data)
  },

  update(id: string, data: Partial<Task>) {
    return api.patch<Task>(`/api/tasks/${id}`, data)
  },

  delete(id: string) {
    return api.delete(`/api/tasks/${id}`)
  },
}
