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 =
    | "inspection"
    | "estimate"
    | "job_card"
    | "invoice"
    | "payment_received"
    | "expense"
    | "purchase_order"
    | "bill"
    | "payment_made"
    | "credit_note"

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 },
        })
    }
}
