import QRCode from 'qrcode';

export class QRGenerator {
  static async generateQR(text: string, options = {}): Promise<string> {
    try {
      // Generate QR code as data URL
      const qrDataUrl = await QRCode.toDataURL(text, {
        width: 256,
        margin: 2,
        color: {
          dark: '#000000',
          light: '#FFFFFF'
        },
        ...options
      });
      return qrDataUrl;
    } catch (error) {
      console.error('QR generation failed:', error);
      throw new Error('QR code generation failed');
    }
  }

  static async generateQRBuffer(text: string, options = {}): Promise<Buffer> {
    try {
      const buffer = await QRCode.toBuffer(text, {
        width: 256,
        margin: 2,
        color: {
          dark: '#000000',
          light: '#FFFFFF'
        },
        ...options
      });
      return buffer;
    } catch (error) {
      console.error('QR buffer generation failed:', error);
      throw new Error('QR code generation failed');
    }
  }
}