import { serverFetchJson } from '@/app/utils/fetchUtil';
import { BASE_API_URL } from '@/config/api';
import { cache } from "react";
import "server-only";

export interface PrinterCombo {
    id: number;
    value: number;
    label?: string;
    code?: string;
    name?: string;
    type?: string;
    brand?: string;
    description?: string;
    ip?: string;
    port?: number;
}

export interface PrinterResult {
    action: any;
    id: number;
    name?: string;
    code?: string;
    type?: string;
    brand?: string;
    description?: string;
    ip?: string;
    port?: number;
    dpi?: number;
}

export const fetchPrinterCombo = cache(async () => {
    return serverFetchJson<PrinterCombo[]>(`${BASE_API_URL}/printers/combo`, {
        next: { tags: ["printers"] },
    })
})

export const fetchPrinters = cache(async () => {
    return serverFetchJson<PrinterResult[]>(`${BASE_API_URL}/printers`, {
        next: { tags: ["printers"] },
    });
});

export const fetchPrinterDescriptions = cache(async () => {
    return serverFetchJson<string[]>(`${BASE_API_URL}/printers/descriptions`, {
        next: { tags: ["printers"] },
    });
});