import io
import qrcode
import qrcode.image.svg
import logging

logger = logging.getLogger(__name__)


def format_cz_payment_data(
        account_number: str,
        recipient_name: str,
        amount: str,
        message: str) -> str:
    """
    Returns formatted payment data for Czech banks
    :param account_number:
    :param recipient_name:
    :param amount:
    :param message:
    :return:
    """
    return f'SPD*1.0*ACC:{account_number}*RN:{recipient_name}*AM:{amount}*CC:CZK*MSG:{message}'

def generate_qr_code_svg(data: str) -> io.BytesIO:
    """
    Generates QR code from data and returns it as SVG image in BytesIO
    :param data:
    :return:
    """
    result = io.BytesIO()
    try:
        qr_code_img = qrcode.make(data, image_factory=qrcode.image.svg.SvgImage)
        qr_code_img.save(result)
        result.seek(0)
    except Exception as e:
        logger.error(e)
        raise e
    return result