from qrdecode.decoder import QRMatrix
import qrcode
import numpy as np

# Here are some tests for the decoder
# No error already introduced in them

# Generate the QRs
qr1 = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,

)
qr1.add_data('hello world')
qr1.make()


qr1n = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_Q,
    box_size=10,
    border=4,

)
qr1n.add_data('12345671234567123')
qr1n.make()


qr2 = qrcode.QRCode(
    version=2,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,

)
qr2.add_data('12345ABCDE12435')
qr2.make()


qr2n = qrcode.QRCode(
    version=2,
    error_correction=qrcode.constants.ERROR_CORRECT_M,
    box_size=10,
    border=4,

)
qr2n.add_data('123456789')
qr2n.make()

qr2 = qrcode.QRColorCode(
    version=2,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,

)
qr2.add_data('12345ABCDE12435')
qr2.make()


qr2n = qrcode.QRColorCode(
    version=2,
    error_correction=qrcode.constants.ERROR_CORRECT_M,
    box_size=10,
    border=4,

)
qr2n.add_data('123456789')
qr2n.make()

qr3 = qrcode.QRCode(
    version=3,
    error_correction=qrcode.constants.ERROR_CORRECT_M,
    box_size=10,
    border=4,

)

qr3.add_data('Even more data')
qr3.make()

qr4 = qrcode.QRCode(
    version=4,
    error_correction=qrcode.constants.ERROR_CORRECT_M,
    box_size=10,
    border=4,

)
qr4.add_data('Wow, so much data')
qr4.make()

qr5 = qrcode.QRCode(
    version=5,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,

)

qr5.add_data('d4t4 d4t4')
qr5.make()

qr6 = qrcode.QRCode(
    version=6,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,

)
qr6.add_data('gimme more and more and more and more D4T4')
qr6.make()

qr7 = qrcode.QRCode(
    version=7,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,

)
qr7.add_data('after party dirty penca')
qr7.make()

qr8 = qrcode.QRCode(
    version=8,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,

)
qr8.add_data('4rr1b4 p4r14s d3 l4 t13rr4')
qr8.make()

# Generate numpy arrays
qr1_array = np.array(qr1.modules, dtype=np.int)
qr1n_array = np.array(qr1n.modules, dtype=np.int)
qr2_array = np.array(qr2.modules, dtype=np.int)
qr2n_array = np.array(qr2n.modules, dtype=np.int)
qr3_array = np.array(qr3.modules, dtype=np.int)
qr4_array = np.array(qr4.modules, dtype=np.int)
qr5_array = np.array(qr5.modules, dtype=np.int)
qr6_array = np.array(qr6.modules, dtype=np.int)
qr7_array = np.array(qr7.modules, dtype=np.int)
qr8_array = np.array(qr8.modules, dtype=np.int)

# Generate QRMatrix objects
qr1m = QRMatrix(qr1_array)
qr1nm = QRMatrix(qr1n_array)
qr2m = QRMatrix(qr2_array)
qr2nm = QRMatrix(qr2n_array)
qr3m = QRMatrix(qr3_array)
qr4m = QRMatrix(qr4_array)
qr5m = QRMatrix(qr5_array)
qr6m = QRMatrix(qr6_array)
qr7m = QRMatrix(qr7_array)
qr8m = QRMatrix(qr8_array)

# Decode QRs
qr1m.decode()
qr1nm.decode()
qr2m.decode()
qr2nm.decode()
qr3m.decode()
qr4m.decode()
qr5m.decode()
qr6m.decode()
qr7m.decode()
qr8m.decode()

# Show images
# img = qr1.make_image()
# img.show()
# img = qr1n.make_image()
# img.show()
img = qr2.make_image()
img.show()
img = qr2n.make_image()
img.show()
# img = qr3.make_image()
# img.show()
# img = qr4.make_image()
# img.show()
# img = qr5.make_image()
# img.show()
# img = qr6.make_image()
# img.show()
# img = qr7.make_image()
# img.show()
# img = qr8.make_image()
# img.show()

