import qrcode

class SPLQR:
    def __init__(self, name: str, upi_id: str):
        self.name = name
        self.upi_id = upi_id

    def generate(self, amount: float, transaction_no: str = None, save_path="upi_qr.png"):
        upi_link = f"upi://pay?pa={self.upi_id}&pn={self.name}&am={amount}&cu=INR"
        if transaction_no:
            upi_link += f"&tn={transaction_no}"

        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=10,
            border=4,
        )
        qr.add_data(upi_link)
        qr.make(fit=True)

        img = qr.make_image(fill_color="black", back_color="white")
        img.save(save_path)
        return save_path
