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

export const PARTS_ROUTES = {
    INDEX: "/api/parts",
    BY_ID: "/api/parts/{id}",
    IMPORT: "/api/parts/import",
    EXPORT: "/api/parts/export",
    TOGGLE_STATUS: "/api/parts/toggle-status",
} as const satisfies Record<string, ApiPath>

export class PartsClient extends CrudClient<
    typeof PARTS_ROUTES.INDEX,
    typeof PARTS_ROUTES.BY_ID
> {
    constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
        super(
            baseUrl,
            defaultOptions,
            PARTS_ROUTES.INDEX,
            PARTS_ROUTES.BY_ID,
            PARTS_ROUTES.IMPORT,
            PARTS_ROUTES.EXPORT,
            "POST",
        )
    }

    async toggleStatus(payload: ApiRequestBody<typeof PARTS_ROUTES.TOGGLE_STATUS, "post">) {
        return this.post(PARTS_ROUTES.TOGGLE_STATUS, payload)
    }
}
