import CoreImage
import CoreImage.CIFilterBuiltins
import CoreGraphics

struct WatchQRCodeService {
    private let context = CIContext()

    func qrCode(from payload: String) -> CGImage? {
        let data = Data(payload.utf8)
        let filter = CIFilter.qrCodeGenerator()
        filter.setValue(data, forKey: "inputMessage")
        filter.correctionLevel = "M"
        guard let outputImage = filter.outputImage else { return nil }
        let scaledImage = outputImage.transformed(by: CGAffineTransform(scaleX: 10, y: 10))
        return context.createCGImage(scaledImage, from: scaledImage.extent)
    }
}
