import { ApiClient, type ApiClientOptions } from "../infra/client"
import type { ApiPath } from "../infra/types"

export const DOCUMENT_PRINT_ROUTES = {
    INDEX: "/api/document-print",
} as const satisfies Record<string, ApiPath>

export type DocumentPrintType = "job_card" | "invoice" | "estimate" | "purchase_order" | "bill" | string

export type DocumentPrintMode = "print" | "download"

export class DocumentPrintClient extends ApiClient {
    constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
        super(baseUrl, defaultOptions)
    }

    async print(type: DocumentPrintType, id: number | string, mode: DocumentPrintMode = "print"): Promise<Blob> {
        return this.fetchBlob(DOCUMENT_PRINT_ROUTES.INDEX, {
            method: "POST",
            body: { type, id: Number(id), mode },
        })
    }
}
