//
//  NotificationService.m
//  NotificationService
//
//  Created by SIUK LEE on 2020/07/07.
//  Copyright © 2020 Smilegate Stove. All rights reserved.
//

#import "NotificationService.h"
#import <SGSPushExtension/SGSPushExtension.h>

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

//    // Modify the notification content here...
//    self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
//
//    NSString *imageURL = [self.bestAttemptContent.userInfo objectForKey:@"image-url"];
//    if (imageURL) {
//
//    } else {
//
//    }
//
//
//    self.contentHandler(self.bestAttemptContent);
    
    [NotificationServiceExtension didReceive:request withContentHandler:contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}

@end
