import type { Options, SearchParams, SearchResponse, SomeRequired, WithId } from './lib' import { request, writeSearchParams } from './lib' /** Task data. */ export interface Task { /** Herd ID. */ _herd: string /** Account ID reflecting the task assignee. */ _account: string /** Description. */ description: string /** Position in herd. */ position: number /** Flag signifying whether the task is done. */ done: boolean } /** Create task request data. */ export interface CreateTaskRequest { task: SomeRequired } /** Create task response data. */ export interface CreateTaskResponse { task: WithId } /** Delete task response data. */ export interface DeleteTaskResponse { task: WithId } /** Get task response data. */ export interface GetTaskResponse { task: WithId } /** Move task response data. */ export interface MoveTaskResponse { task: WithId tasks: { affectedCount: number } } /** Toggle task done response data. */ export interface ToggleTaskDoneResponse { task: WithId } /** Update task request data. */ export interface UpdateTaskRequest { task: Partial } /** Update task response data. */ export interface UpdateTaskResponse { task: WithId } /** Create a task. */ export async function createTask(opt: Options, data: CreateTaskRequest): Promise { return request(opt, 'POST', '/task', undefined, data) } /** Delete a task. */ export async function deleteTask(opt: Options, id: string): Promise { return request(opt, 'DELETE', `/task/${id}`) } /** Get a task. */ export async function getTask(opt: Options, id: string): Promise { return request(opt, 'GET', `/task/${id}`) } /** Move a task. */ export async function moveTask(opt: Options, id: string, position: number): Promise { return request(opt, 'PATCH', `/task/${id}/move/${position}`) } /** Search tasks. */ export async function searchTasks(opt: Options, herd?: string, params?: SearchParams): Promise> { return request(opt, 'GET', herd ? `/herd/${herd}/tasks` : '/tasks', params && writeSearchParams(params)) } /** Toggle task done status. */ export async function toggleTaskDone(opt: Options, id: string): Promise { return request(opt, 'PATCH', `/task/${id}/done`) } /** Update a task. */ export async function updateTask(opt: Options, id: string, data: UpdateTaskRequest): Promise { return request(opt, 'PUT', `/task/${id}`, undefined, data) }