import client from './client'

export const tasksApi = {
  list: async (completed = null) => {
    let url = 'tasks'
    if (completed !== null) {
      url += `?completed=${completed}`
    }
    const res = await client.get(url)
    return res.data
  },

  today: async () => {
    const res = await client.get('tasks/today')
    return res.data
  },

  get: async (id) => {
    const res = await client.get(`tasks/${id}`)
    return res.data
  },

  create: async (data) => {
    const res = await client.post('tasks', data)
    return res.data
  },

  update: async (id, data) => {
    const res = await client.put(`tasks/${id}`, data)
    return res.data
  },

  delete: async (id) => {
    await client.delete(`tasks/${id}`)
  },

  complete: async (id) => {
    const res = await client.post(`tasks/${id}/complete`)
    return res.data
  },

  uncomplete: async (id) => {
    const res = await client.post(`tasks/${id}/uncomplete`)
    return res.data
  },
}
