import generateQrCode from "sepa-payment-qr-code";
import QRCode from "qrcode";
import { WIRE_GIROCODE_RECIPIENT } from "../config/wireGirocodeRecipient.js";

/**
 * @param {{ amount: number, reference: string }} options
 * @returns {Promise<string>} data URL for a PNG QR image
 */
export async function buildWireGirocodeDataUrl({ amount, reference }) {
  const epcText = generateQrCode({
    name: WIRE_GIROCODE_RECIPIENT.name,
    iban: WIRE_GIROCODE_RECIPIENT.iban,
    bic: WIRE_GIROCODE_RECIPIENT.bic,
    amount,
    unstructuredReference: String(reference),
  });

  return QRCode.toDataURL(epcText, {
    errorCorrectionLevel: "M",
    width: 200,
    margin: 1,
    color: {
      dark: "#000000",
      light: "#FFFFFF",
    },
  });
}
