//
//  VFYIdReviewWrapper.m
//  Verif-y Neo
//
//  Created by MTN on 3/19/21.
//

#import "VFYIdReviewWrapper.h"
#import "VFYIDSelfieGuideWrapper.h"
#import "Utilities.h"
#import "VFYConstant.h"
#import "VFYButton.h"
#import "VFYSuggestionPopup.h"
#import "VFYAuditManager.h"

@interface VFYIdReviewWrapper ()

/** IBoutlet for UIButton */
@property (weak, nonatomic) IBOutlet VFYButton *btnContinue;
@property (weak, nonatomic) IBOutlet VFYButton *btnTryAgain;
@property (weak, nonatomic) IBOutlet VFYButton *btnContinueSuccess;
@property (weak, nonatomic) IBOutlet UIView *successBtnContainer;
@property (strong, nonatomic) NSMutableArray *failedValidateCount;
//@property (nonatomic, strong) NSArray *documentType;
@property (strong, nonatomic) UIColor *fontColor;
@property (strong, nonatomic) UIColor *headerColor;
@property (strong, nonatomic) UIColor *backgroundColor;
@property (strong, nonatomic) UIColor *headerFontColor;
/** IBoutlet for extra varibles */
@property (weak, nonatomic) IBOutlet UIScrollView *bodyScrollView;
@property (strong, nonatomic) VFYIDSuccess *idSuccess;
/** Error label */
@property (weak, nonatomic) IBOutlet UILabel *lblErrFirstName;
@property (weak, nonatomic) IBOutlet UILabel *lblErrLastName;
@property (weak, nonatomic) IBOutlet UILabel *lblErrDateOfBirth;
@property (weak, nonatomic) IBOutlet UIImageView *successImage;
@property (nonatomic, strong) NSBundle *bundlePath;

@end

@implementation VFYIdReviewWrapper

@synthesize sharedInstance;
@synthesize callDirectlyFlag;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (@available(iOS 13.0, *)) {
         self.view.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
    self.bundlePath = [NSBundle bundleForClass:[VFYVerifyApp class]];
    self.lblErrFirstName.text = @"";
    self.lblErrLastName.text = @"";
    self.lblErrDateOfBirth.text = @"";
    self.successImage.image = nil;
    
    self.btnContinue.hidden = FALSE;
    self.btnTryAgain.hidden = FALSE;
    self.successBtnContainer.hidden = TRUE;
    
    self.failedValidateCount = [NSMutableArray new];
    self.idSuccess = [[VFYIDSuccess alloc] init];
    //[self.view setBackgroundColor:[Utilities colorFromColorString:self.sharedInstance.bodyColor]];
    [self.bodyScrollView setBackgroundColor:[Utilities colorFromColorString:self.sharedInstance.bodyColor]];
    self.sharedInstance = [VFYVerifyApp sharedInstance];
    /** observer is use to receive values from Nth child to current view */
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(idSuccessCallFromNthChild:) name:VFY_OBSERVER_IDSUCCESS object:nil];
    self.fontColor = [Utilities colorFromColorString:self.sharedInstance.bodyTextColor];
    self.headerColor = [Utilities colorFromColorString:self.sharedInstance.headerColor];
    self.backgroundColor = [Utilities colorFromColorString:self.sharedInstance.bodyColor];
    self.headerFontColor = [Utilities colorFromColorString:self.sharedInstance.headerTextColor];
    [self setLocalizationText];
    [self setBrandingColor];
    [self setValues];
}

/** Receive method use to handle call from nth child */
- (void) idSuccessCallFromNthChild:(NSNotification *)notify {
    NSLog(@"dataReceived :%@", notify.object);
    VFYIDSuccess *vfySuccess = (VFYIDSuccess*)notify.object;
    [self.idGuide callClose:IDSuccessComplete PassValue:vfySuccess];
}

/**
  Add color to branding and corner button
*/
- (void) setBrandingColor {
    /* Set button style */
    [self.btnContinue animateOnPress:FALSE borderColor:[Utilities colorFromColorString:[self.sharedInstance buttonBorderColor]] backGroundColor:[Utilities colorFromColorString:[self.sharedInstance buttonBackgroundColor]] textColor:[Utilities colorFromColorString:[self.sharedInstance buttonTextColor]]];
    [self.btnTryAgain animateOnPress:FALSE borderColor:[Utilities colorFromColorString:[self.sharedInstance buttonBorderColor]] backGroundColor:[Utilities colorFromColorString:[self.sharedInstance buttonBackgroundColor]] textColor:[Utilities colorFromColorString:[self.sharedInstance buttonTextColor]]];
    [self.btnContinueSuccess animateOnPress:FALSE borderColor:[Utilities colorFromColorString:[self.sharedInstance buttonBorderColor]] backGroundColor:[Utilities colorFromColorString:[self.sharedInstance buttonBackgroundColor]] textColor:[Utilities colorFromColorString:[self.sharedInstance buttonTextColor]]];
     [self CustomTitle];
}

/** Set the extracted values to page */
- (void) setValues {
    MBBlinkIdCombinedRecognizer *mbCombine = self.recognizerCollection;
    
    self.idSuccess.isSuccessful = true;
    
    if(mbCombine.result.address != nil) {
        self.idSuccess.extractedAddress = mbCombine.result.address;
    }
    if(mbCombine.result.faceImage.image != nil) {
        self.idSuccess.faceImage = [Utilities compressPNGBase64:mbCombine.result.faceImage.image];
    }
    if(mbCombine.result.fullDocumentFrontImage.image != nil) {
        self.idSuccess.documentFrontImage = [Utilities compressPNGBase64:mbCombine.result.fullDocumentFrontImage.image];
    }
    if(mbCombine.result.fullDocumentBackImage.image != nil) {
        self.idSuccess.documentBackImage = [Utilities compressPNGBase64:mbCombine.result.fullDocumentBackImage.image];
    }
    //First name
    NSString *firstName = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.secondaryID length] == 0) ? mbCombine.result.firstName : mbCombine.result.mrzResult.secondaryID : mbCombine.result.firstName;
    self.idSuccess.extractedFirstName = [firstName capitalizedString];
    
    //Last name
    NSString *lastName = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.primaryID length] == 0) ? mbCombine.result.lastName : mbCombine.result.mrzResult.primaryID : mbCombine.result.lastName;
    self.idSuccess.extractedLastName = [lastName capitalizedString];
    
    //Gender
    NSString *gender = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.gender length] == 0) ? mbCombine.result.sex : mbCombine.result.mrzResult.gender : mbCombine.result.sex;
    if([gender length]>0 && [@"f" caseInsensitiveCompare:gender] == NSOrderedSame) {
        gender = @"female";
    } else if([gender length]>0 && [@"m" caseInsensitiveCompare:gender] == NSOrderedSame) {
        gender = @"male";
    }
    self.idSuccess.extractedGender = [gender capitalizedString];
    
    //Document number
    NSString *docNumber = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.documentNumber length] == 0) ? mbCombine.result.documentNumber : mbCombine.result.mrzResult.documentNumber : mbCombine.result.documentNumber;
    self.idSuccess.extractedIdDocumentNumber = [docNumber stringByReplacingOccurrencesOfString:@"<" withString:@""];
    
    //Document Type
    self.idSuccess.extractedDocumentType = [self getDocumentType:mbCombine];
    
    //Date of Birth
    self.idSuccess.extractedDateOfBirth = [self getDateOfBirth:mbCombine];
    
    //Date of expire
    self.idSuccess.extractedDateOfExpire = [self getDateOfExpire:mbCombine];
    
    //Nationality
    self.idSuccess.extractedNation = [self getNationality:mbCombine];
    
    //Issuer
    self.idSuccess.extractedIssuer = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.issuer length] == 0) ? mbCombine.result.issuingAuthority : mbCombine.result.mrzResult.issuer : mbCombine.result.issuingAuthority;

    [self showExtractedSuggestedPopup];
    [self validationCheck];
    if([self.failedValidateCount count] == 9){
        //When all the extracted filed are empty
        self.lblErrFirstName.text = @""; self.lblErrLastName.text = @""; self.lblErrDateOfBirth.text = @"";
        NSString *strMessage = NSLocalizedStringWithDefaultValue(@"mb_valdiationCard_empty_fields", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"This document is not supported. Please try again.", nil);
        [self displayMessage:self.lblErrDateOfBirth Message:strMessage Value:@"" FieldTag:FirstName];
    } else if([self.failedValidateCount count] < 9) {
        //When any one field get extracted other than first, last and date of birth
        if([self.lblErrDateOfBirth.text length] == 0 && [self.lblErrFirstName.text length] == 0 && [self.lblErrLastName.text length] == 0){
            self.successImage.image = [UIImage imageNamed:@"vfy-review-success.png"];
            self.successBtnContainer.hidden = false;
            self.btnContinue.hidden = true;
            self.btnTryAgain.hidden = true;
        }
    }
}

- (NSString*) getNationality:(MBBlinkIdCombinedRecognizer *) mbCombine {
    NSString *nation = @"";
    nation = (mbCombine.result.mrzResult) ? ([mbCombine.result.mrzResult.nationality length] == 0) ? mbCombine.result.nationality : mbCombine.result.mrzResult.nationality : mbCombine.result.nationality;
    if([nation length] == 0) nation = mbCombine.result.classInfo.countryName;
    return nation;
}

- (NSDate*) getNsdate:(NSString*) date {
    NSDate *setDate = [NSDate date];
    if([date length]>0) {
        NSString *dateStr = date;
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:VFY_IDENTITY_DATEFORMATE];
        setDate = [dateFormat dateFromString:dateStr];
    }
    return setDate;
}

- (NSString *) getDateOfBirth:(MBBlinkIdCombinedRecognizer *) mbCombine {
    NSString *combineString=@"";
    if(mbCombine.result.mrzResult){
        combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.mrzResult.dateOfBirth.day, mbCombine.result.mrzResult.dateOfBirth.month, mbCombine.result.mrzResult.dateOfBirth.year];
        if(mbCombine.result.mrzResult.dateOfBirth.month == 0 && mbCombine.result.mrzResult.dateOfBirth.day == 0 && mbCombine.result.mrzResult.dateOfBirth.year == 0){
            combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.dateOfBirth.day, mbCombine.result.dateOfBirth.month, mbCombine.result.dateOfBirth.year];
        }
    } else {
        combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.dateOfBirth.day, mbCombine.result.dateOfBirth.month, mbCombine.result.dateOfBirth.year];
    }
    return combineString;
}

- (NSString *) getDateOfExpire:(MBBlinkIdCombinedRecognizer *) mbCombine {
    NSString *combineString=@"";
    if(mbCombine.result.mrzResult){
        combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.mrzResult.dateOfExpiry.day, mbCombine.result.mrzResult.dateOfExpiry.month, mbCombine.result.mrzResult.dateOfExpiry.year];
        if(mbCombine.result.mrzResult.dateOfExpiry.month == 0 && mbCombine.result.mrzResult.dateOfExpiry.day == 0 && mbCombine.result.mrzResult.dateOfExpiry.year == 0){
            combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.dateOfExpiry.day, mbCombine.result.dateOfExpiry.month, mbCombine.result.dateOfExpiry.year];
        }
    } else {
        combineString = [NSString stringWithFormat:@"%ld/%ld/%ld",mbCombine.result.dateOfExpiry.day, mbCombine.result.dateOfExpiry.month, mbCombine.result.dateOfExpiry.year];
    }
    return combineString;
}

/**
  Add localization text on labels
*/
- (void) setLocalizationText {
    /* Set localization on button */
    [self.btnContinue setTitle:NSLocalizedStringWithDefaultValue(@"mb_identity_button_1", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Continue", nil) forState:UIControlStateNormal];
    [self.btnTryAgain setTitle:NSLocalizedStringWithDefaultValue(@"mb_identity_button_2", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Continue", nil) forState:UIControlStateNormal];
}

/**
  Add Header title test or image
*/
-(void) CustomTitle {
    if([self.sharedInstance.headerTitleImage length]>0){
       [Utilities customTitleImage:self.navigationItem Logo:self.sharedInstance.headerTitleImage];
    } else if([self.sharedInstance.headerTitleText length]){
        [Utilities customTitleText:self.navigationItem TitleText:self.sharedInstance.headerTitleText FontColor:self.sharedInstance.headerTextColor];
    }
}

- (IBAction)btnContinue:(id)sender {
    [self submitSuccess];
}

- (IBAction)btnTryAgain:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)btnContinueSuccess:(id)sender {
    [self submitSuccess];
}

- (void) submitSuccess {
    [self callAudit];
    if(callDirectlyFlag == Directly) {
       [self.idGuide callClose:IDSuccessComplete PassValue:self.idSuccess];
    } else if(callDirectlyFlag == InDirectly) {
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:VFY_MAIN_STORYBOARD bundle:self.bundlePath];
       VFYIDSelfieGuideWrapper *newView = [storyboard instantiateViewControllerWithIdentifier:VFY_SELFIE_STORYBOARD];
       newView.idSuccess = self.idSuccess;
       [self.navigationController pushViewController:newView animated:YES];
    }
}

/**
  Validation check method
*/
- (void)validationCheck {
    self.failedValidateCount = [NSMutableArray new];
    for (int i=901; i <= 908; i++) {
         [self emptyTextfieldValidation:i];
    }
    if ([self.idSuccess.extractedAddress isEqualToString:@""]) {
        [self.failedValidateCount addObject:[NSString stringWithFormat: @"%d", Address]];
    }
}

/**
      Validation as per the textfields
*/
- (void) emptyTextfieldValidation :(int) fieldName {
    NSString *strMessage = [NSString string];
    switch (fieldName) {
        case FirstName:
            {
                strMessage = NSLocalizedStringWithDefaultValue(@"mb_valdiationIdentity_empty_errfirstname", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Firstname is empty!", nil);
                [self displayMessage:self.lblErrFirstName Message:strMessage Value:self.idSuccess.extractedFirstName FieldTag:FirstName];
                break;
            }
        case LastName:
            {
                strMessage = NSLocalizedStringWithDefaultValue(@"mb_valdiationIdentity_empty_errlastname", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Lastname is empty!", nil);
                [self displayMessage:self.lblErrLastName Message:strMessage Value:self.idSuccess.extractedLastName FieldTag:LastName];
                break;
            }
        case Gender:
            {
                [self displayMessage:nil Message:@"" Value:self.idSuccess.extractedGender FieldTag:Gender];
                break;
            }
        case DocumentNumber:
            {
                [self displayMessage:nil Message:@"" Value:self.idSuccess.extractedIdDocumentNumber FieldTag:DocumentNumber];
                break;
            }
        case DocumentType:
            {
                [self displayMessage:nil Message:@"" Value:self.idSuccess.extractedDocumentType FieldTag:DocumentType];
                break;
            }
        case DateOfBirth:
            {
                //strMessage = NSLocalizedStringWithDefaultValue(@"mb_valdiationIdentity_empty_errdateOfBirth", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Date of birth is empty!", nil);
                [self displayMessage:nil Message:strMessage Value:self.idSuccess.extractedDateOfBirth FieldTag:DateOfBirth];
                NSString  *strMessage = NSLocalizedStringWithDefaultValue(@"mb_valdiationIdentity_erragelimitdateOfBirth", [self.sharedInstance language], [self.sharedInstance languageBundlePath], @"Age of user is below minimum allowed age!", nil);
                [self checkForAgeLimit:self.lblErrDateOfBirth Message:strMessage Value:self.idSuccess.extractedDateOfBirth FieldTag:DateOfBirth];
                break;
            }
        case DateOfExpiration:
            {
                [self displayMessage:nil Message:@"" Value:self.idSuccess.extractedDateOfExpire FieldTag:DateOfExpiration];
                break;
            }
        case Nationality:
            {
                [self displayMessage:nil Message:@"" Value:self.idSuccess.extractedNation FieldTag:Nationality];
                break;
            }
        default:
            break;
    }
}

- (void) displayMessage: (UILabel*) labelName Message:(NSString*)message Value:(NSString*) value FieldTag:(successFieldNames) fieldTag {
    if ((value == nil || [value isEqualToString:@""]) || [value isEqualToString:@"0/0/0"]) {
        [self.failedValidateCount addObject:[NSString stringWithFormat: @"%d", fieldTag]];
        if(labelName != nil){
            labelName.hidden = false;
            labelName.text = message;
            labelName.textColor = [UIColor redColor];
        }
    }
}

/**
  Call the suggestion popup when assign the extracted value
*/
- (void) showExtractedSuggestedPopup {
    bool suggestionFlag = self.sharedInstance.suggestionValidation;
    NSString *accountName = [NSString string];
    NSString *cardName = [NSString string];
    if([self.sharedInstance.accountOwnerFirstName length]>0 || [self.sharedInstance.accountOwnerLastName length] > 0){
        accountName = [NSString stringWithFormat:@"%@ %@", self.sharedInstance.accountOwnerFirstName, self.sharedInstance.accountOwnerLastName];
        accountName = [accountName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    }
    if([self.sharedInstance.cardOwnerFirstName length]>0 || [self.sharedInstance.cardOwnerLastName length] > 0){
        cardName = [NSString stringWithFormat:@"%@ %@", self.sharedInstance.cardOwnerFirstName, self.sharedInstance.cardOwnerLastName];
        cardName = [cardName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    }
    NSString *extractedIdName = [NSString stringWithFormat:@"%@ %@", self.idSuccess.extractedFirstName, self.idSuccess.extractedLastName];
    extractedIdName = [extractedIdName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if(suggestionFlag && ([cardName length] > 0 || [accountName length] > 0)){
        if(([cardName caseInsensitiveCompare:extractedIdName] != NSOrderedSame) && ([accountName caseInsensitiveCompare:extractedIdName] != NSOrderedSame)){
            [self pushSuggestedPopup];
        } else if([extractedIdName length] == 0) {
            [self pushSuggestedPopup];
        }
    }
}

/**
  Push the suggestion popup
*/
- (void) pushSuggestedPopup {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:VFY_MAIN_STORYBOARD bundle:self.bundlePath];
    VFYSuggestionPopup *vc = [storyboard instantiateViewControllerWithIdentifier:@"VFYSuggestion"];
    vc.popupSelf = (id)self;
    vc.callMethodFlag = IDExtract;
    vc.extFirstName = self.idSuccess.extractedFirstName;
    vc.extLastName = self.idSuccess.extractedLastName;
    vc.accOwnerFrstName = self.sharedInstance.accountOwnerFirstName;
    vc.accOwnerLstName = self.sharedInstance.accountOwnerLastName;
    vc.crdOwnerFrstName = self.sharedInstance.cardOwnerFirstName;
    vc.crdOwnerLstName = self.sharedInstance.cardOwnerLastName;
    [self presentViewController:vc animated:YES completion:nil];
}


/**
  Handle the callback from the popup view
*/
- (void) callBackFromPopupClose:(popupCallFromMethod)methodName PassValue:(NSString*)passValue {
    if(methodName == IDExtract){
        if(passValue != nil){
            self.lblErrFirstName.text = @" ";
            self.lblErrLastName.text = @" ";
            self.idSuccess.editedFirstName = [[passValue valueForKey:@"firstname"] capitalizedString];
            self.idSuccess.editedLastName = [[passValue valueForKey:@"lastname"] capitalizedString];
            if([self.lblErrDateOfBirth.text length] == 0){
                self.successImage.image = [UIImage imageNamed:@"vfy-review-success.png"];
                self.successBtnContainer.hidden = false;
                self.btnContinue.hidden = true;
                self.btnTryAgain.hidden = true;
            }
        }
    }
}

/**
   Display the card validation message
*/
- (void) checkForAgeLimit: (UILabel*) labelName Message:(NSString*)message Value:(NSString*) value FieldTag:(successFieldNames) fieldTag {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:VFY_IDENTITY_DATEFORMATE];
    NSDate *date = [dateFormatter dateFromString:value];
    if (![value isEqualToString:@""] && ![value isEqualToString:@"0/0/0"]) {
        if ([self validateDOB:date]) {
            [self.failedValidateCount addObject:[NSString stringWithFormat: @"%d", fieldTag]];
            labelName.hidden = false;
            labelName.text = message;
            labelName.textColor = [UIColor redColor];
        } else {
            if(!labelName.hidden){
               labelName.hidden = true;
               labelName.text = @"";
            }
        }
    }
}

/**
  Validate date of birth
*/
- (bool) validateDOB:(NSDate *)dateDOB {
    NSInteger currYear;
    NSInteger dobirthYear;
    NSInteger age = 0;
    bool returnValue=false;
    NSInteger ageLimit;
    if([[self.sharedInstance minimumAgeLimit] length] > 0){
        ageLimit = [[self.sharedInstance minimumAgeLimit] integerValue];
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];
    NSString *currentYear = [formatter stringFromDate:[NSDate date]];
    NSString *dobYear = [formatter stringFromDate:dateDOB];
    if([currentYear length] > 0 && [dobYear length] > 0){
        currYear = [currentYear integerValue];
        dobirthYear = [dobYear integerValue];
        age = currYear - dobirthYear;
        if(getDaysInYear([NSDate date]) < getDaysInYear(dateDOB)){
            age--;
        }
        if(age < ageLimit){
            returnValue = true;
        }
    }
    return returnValue;
}

/**
  Get the days of years
*/
/*NSInteger getDaysInYear(NSDate* date) {
    NSCalendar *currentCalendar = [NSCalendar currentCalendar];
    NSDate *today = date;
    NSInteger dc = [currentCalendar ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:today];
    return dc;
} */

/**
    Get the document type as per the MRZ result and user info
*/
- (NSString *) getDocumentType :(MBBlinkIdCombinedRecognizer *) mbCombine {
    NSString *setDocumentType = @"";
    if(mbCombine.result.mrzResult) {
        NSString *dcType =  [self getDocumentTypeFrmMRZ:mbCombine.result.mrzResult.documentType];
        if([dcType isEqualToString:@"Unknown"]){
            setDocumentType = [self getDocumentTypeFrmUserInfo:mbCombine.result.classInfo.type];
        } else {
            setDocumentType = dcType;
        }
    } else if(mbCombine.result.classInfo) {
        setDocumentType = [self getDocumentTypeFrmUserInfo:mbCombine.result.classInfo.type];
    }
    return setDocumentType;
}

/**
    Get the document type as per the MRZ result
*/
- (NSString *) getDocumentTypeFrmMRZ :(NSInteger) documentType {
    NSString *setDocumentType = @"Unknown";
    switch (documentType) {
        case 0:
            setDocumentType = @"Unknown";
            break;
        case 1:
            setDocumentType = @"IdentityCard";
            break;
        case 2:
            setDocumentType = @"Passport";
            break;
        case 3:
            setDocumentType = @"Visa";
            break;
        case 4:
            setDocumentType = @"GreenCard";
            break;
        case 5:
            setDocumentType = @"Malaysian PASS IMM13P";
            break;
        case 6:
            setDocumentType = @"One liner ISO DL";
            break;
        case 7:
            setDocumentType = @"Internal TravelDocument";
            break;
        default:
            break;
    }
    return setDocumentType;
}

/**
    Get the document type as per the user info
*/
- (NSString *) getDocumentTypeFrmUserInfo :(NSInteger) documentType {
    NSString *setDocumentType = @"Unknown";
    switch (documentType) {
        case 0:
            setDocumentType = @"Unknown";
            break;
        case 1:
            setDocumentType = @"Consular Id Card";
            break;
        case 2:
            setDocumentType = @"Driver's License";
            break;
        case 3:
            setDocumentType = @"Public Services Card";
            break;
        case 4:
            setDocumentType = @"Employment Pass";
            break;
        case 5:
            setDocumentType = @"FinCard";
            break;
        case 6:
            setDocumentType = @"Identity Card";
            break;
        case 7:
            setDocumentType = @"Multipurpose Id";
            break;
        case 8:
            setDocumentType = @"MyKad";
            break;
        case 9:
            setDocumentType = @"MyKid";
            break;
        case 10:
            setDocumentType = @"MyPR";
            break;
        case 11:
            setDocumentType = @"MyTentera";
            break;
        case 12:
            setDocumentType = @"PanCard";
            break;
         case 13:
            setDocumentType = @"Professional Id";
            break;
         case 14:
            setDocumentType = @"PublicServices Card";
            break;
         case 15:
            setDocumentType = @"Residence Permit";
            break;
         case 16:
            setDocumentType = @"Resident Id";
            break;
         case 17:
            setDocumentType = @"Temporary Residence Id";
            break;
         case 18:
            setDocumentType = @"Voter Id";
            break;
         case 19:
            setDocumentType = @"Work Permit";
            break;
         case 20:
            setDocumentType = @"iKad";
            break;
         case 21:
            setDocumentType = @"Military Id";
            break;
         case 22:
            setDocumentType = @"MyKas";
            break;
         case 23:
            setDocumentType = @"SocialSecurity Card";
            break;
         case 24:
            setDocumentType = @"HealthInsurance Card";
            break;
         default:
            break;
    }
    return setDocumentType;
}

- (void) callAudit {
    NSMutableDictionary *setting = [NSMutableDictionary dictionary];
    self.auditEventDuration = CACurrentMediaTime() - self.auditEventDuration;
    if(self.auditEventDuration) {
        NSString *eventDuration = [Utilities stringFromTimeInterval:self.auditEventDuration];
        NSString *scanDuration = [Utilities stringFromTimeInterval:self.auditScanDuration];
        [setting setValue:eventDuration forKey:@"audit_event_duration"];
        [setting setValue:scanDuration forKey:@"audit_scan_Duration"];
    } else {
        [setting setValue:@"" forKey:@"audit_event_duration"];
        [setting setValue:@"" forKey:@"audit_scan_Duration"];
    }
    [VFYAuditManager idSuccessAudit:self.idSuccess settings:setting completed:^(NSString *response) {
        NSLog(@"Id success response %@",response);
    } failure:^(NSError *error){
        NSLog(@"Id success response error : %@",error);
    }];
}

@end
