'''
Created on Jun 12, 2020

@author Saurabh Kumar Pandey
'''


def validation(input_data, user_type):
#     if not will be used for strings check
    try:
        validation_flag = True
        missing_data = {}    
        if user_type == 'non_aadhaar':
            mustfields = ('digilockerid','date_of_birth','gender','name','mobile_no') #'aadhaarno','user_type'   
            for field in mustfields:
                if not input_data[field]:
                    missing_data[field] = input_data[field] 
                    validation_flag = False
            return {'status': validation_flag, 'msg': missing_data}
        elif user_type == 'demographic':        
            mustfields = ('digilockerid','date_of_birth','gender','name','mobile_no', 'uid') #'aadhaarno','user_type'   
            for field in mustfields:
                if not input_data[field]:
                    missing_data[field] = input_data[field] 
                    validation_flag = False
            return {'status': validation_flag, 'msg': missing_data}
        elif user_type == 'aadhaar':        
            mustfields = ('digilockerid','date_of_birth','gender','name', 'uid', 'uid_token') #'aadhaarno','user_type'   
            for field in mustfields:
                if not input_data[field]:
                    missing_data[field] = input_data[field] 
                    validation_flag = False
                    
                if field == 'uid_token' and len(input_data['uid_token']) != 72:
                    validation_flag = False
                      
            return {'status': validation_flag, 'msg': missing_data}
        
        elif user_type == 'mysql':        
            mustfields = ('digilockerid','pin','password') #'aadhaarno','user_type'   
            for field in mustfields:
                if not input_data[field]:
                    missing_data[field] = input_data[field] 
                    validation_flag = False                      
            return {'status': validation_flag, 'msg': missing_data}
        else:
            validation_flag = False
            return {'status': validation_flag, 'msg': missing_data}
    except Exception as DataError:
        return {'status': validation_flag, 'msg': missing_data, 'exp': str(DataError)}    
 
      
#entry point OVER    