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

export const APPOINTMENT_ROUTES = {
    INDEX: "/api/appointments",
    BY_ID: "/api/appointments/{id}",
    UNLINK_JOB_CARD: "/api/appointments/{id}/un-link-job-card",
    CHANGE_STATUS: "/api/appointments/{id}/change-status",
} as const satisfies Record<string, ApiPath>

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

    async unlinkJobCard(id: string, payload: ApiRequestBody<typeof APPOINTMENT_ROUTES.UNLINK_JOB_CARD, "post">) {
        return this.post(APPOINTMENT_ROUTES.UNLINK_JOB_CARD, payload, { params: { id } })
    }

    async changeStatus(id: string, payload: ApiRequestBody<typeof APPOINTMENT_ROUTES.CHANGE_STATUS, "post">) {
        return this.post(APPOINTMENT_ROUTES.CHANGE_STATUS, payload, { params: { id } })
    }
}
