#import "ContextAwareAdinCubeUserConsentDelegate.h"

#define USER_CONSENT_EVENT_PREFIX @"AIC-UserConsent-"

@implementation ContextAwareAdinCubeUserConsentDelegate

- (void)didCompleteAsk:(AdinCubeUserConsentAnswer)answer {
	[self dispatchJavascriptEvent:USER_CONSENT_EVENT_PREFIX @"onAskComplete" content:[self nameForAnswer:answer]];
}

- (void)didFailToAsk:(NSString*)errorCode {
	[self dispatchJavascriptEvent:USER_CONSENT_EVENT_PREFIX @"onAskError" content:errorCode];
}

- (void)didCompleteEdit:(AdinCubeUserConsentAnswer)answer {
	[self dispatchJavascriptEvent:USER_CONSENT_EVENT_PREFIX @"onEditComplete" content:[self nameForAnswer:answer]];
}

- (void)didFailToEdit:(NSString*)errorCode {
	[self dispatchJavascriptEvent:USER_CONSENT_EVENT_PREFIX @"onEditError" content:errorCode];
}

- (NSString*)nameForAnswer:(AdinCubeUserConsentAnswer)answer {
    switch (answer) {
        case AdinCubeUserConsentAnswerFullApproval:
            return @"FULL_APPROVAL";
        case AdinCubeUserConsentAnswerPartialApproval:
            return @"PARTIAL_APPROVAL";
        case AdinCubeUserConsentAnswerRefusal:
            return @"REFUSAL";
        case AdinCubeUserConsentAnswerNoAnswer:
            return @"NO_ANSWER";
    }
}

@end