import qrcode,os, random,string 
from pathlib import Path
def get_QR_Image(str_text, str_filename):
    file_fullname = os.path.join(os.path.dirname(Path(__file__).resolve().parent.parent) + '\\static\\temp\\img',str_filename +'.jpg')
    #file_fullname = os.path.join(os.path.dirname(os.path.dirname(__file__)) + '\\Lib\\img',str_filename +'.jpg')

    print(file_fullname)
    img = qrcode.make(str_text)
    img.save(file_fullname)
    return '/temp/img/'+ str_filename +'.jpg'

def generate_UPI_QR(obj_file):
    str_QRText = "upi://pay?cu=INR&pa=" + obj_file.pay_by.UPIID + "&pn=" + obj_file.pay_by.regname + "&tn=" + str(obj_file.id) + "&am=" + str(obj_file.order_amount)
    #str_QRText = "upi://pay?cu=INR&pa=gtscollect@icici&pn=GideonGardenTechnologyandServicesprivatelimited&tn=132&am=3.0"
    print(str_QRText)
    str_fileloc = get_QR_Image(str_QRText, str(obj_file.id))
    return str_fileloc

# dictionary list to values 

def get_list_from_dict(list_data, str_key): 
    list_output = []
    for dic_data in list_data:  list_output.append(dic_data[str_key]) 
    return list_output

# random functions 

def get_random_list_from_choice(list_data, int_max):
    list_output = []
    for counter  in range(0,int_max, +1):
        list_output.append(random.choice(list_data))
    return list_output

def get_password(p_length =13):
    str_symbols = '!@#$%^&*()'
    str_pass = ''
    for counter  in range(1,p_length, +1):
       if  counter % 5 == 0 : 
            str_pass = str_pass + random.choice(string.ascii_letters)
       elif  counter % 3 == 0 : 
            str_pass = str_pass + random.choice(str_symbols)   
       else:
            str_pass = str_pass + random.choice(string.digits)
    return str_pass    

def get_random_character(p_length =13):
    str_pass = ''
    for counter  in range(1,p_length, +1):        str_pass = str_pass + random.choice(string.ascii_letters)
    return str_pass  

def get_random_number(p_length =13):
    str_pass = ''
    for counter  in range(1,p_length, +1):        str_pass = str_pass + random.choice(string.digits)
    return str_pass  



def get_random_list(p_length =[]):
    str_pass = ''
    for counter  in range(1,p_length, +1):        str_pass = str_pass + random.choice(string.digits)
    return str_pass  


# def internal_test():
#     list_output = []
#     list_report_IMH_group = ['children_1_5', 'children_6_12', 'male_12_25', 'male_25_40', 'male_40_60', 'male_gt_60', 'female_12_25','female_25_40', 'female_40_60','female_gt_60']
#     list_report_IMH_group_name = ['children 1 to 5', 'children 6 to 12', 'male 12 to 25', 'male 25 to 40', 'male 40 to 60', 'male more than 60', 'female 12 to 25','female 25 to 40', 'female 40 to 60','female more than 60']
#     int_counter = 0 
#     for list_data in list_report_IMH_group:
#         dic_output = {}
#         dic_output['header'] =         list_data
#         dic_output['title'] =         list_report_IMH_group_name[int_counter]
#         list_output.append(dic_output)
#         int_counter= int_counter+ 1
#     return list_output

# print(internal_test())
