import { CrudClient } from "../infra/crud-client"
import type { ApiClientOptions } from "../infra/client"
import type { ApiPath, ApiRequestBody } from "../infra/types"

export const TASK_ROUTES = {
    INDEX: "/api/tasks",
    BY_ID: "/api/tasks/{id}",
    COMPLETE: "/api/tasks/{id}/complete",
} as const satisfies Record<string, ApiPath>

export class TasksClient extends CrudClient<
    typeof TASK_ROUTES.INDEX,
    typeof TASK_ROUTES.BY_ID
> {
    constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
        super(baseUrl, defaultOptions, TASK_ROUTES.INDEX, TASK_ROUTES.BY_ID)
    }

    async complete(id: string, payload: ApiRequestBody<typeof TASK_ROUTES.COMPLETE, "post">) {
        return this.post(TASK_ROUTES.COMPLETE, payload, { params: { id } })
    }
}
