//
//  AppDelegate.m
//  macOS (App)
//
//  Created by Tomek Wójcik on 21/08/2025.
//

#import "AppDelegate.h"

#import "HPAuthFlow.h"
#import "HPCredentialsHelper.h"

@implementation AppDelegate

-(void)applicationDidFinishLaunching:(NSNotification *)notification {
    self.authFlow = [[HPAuthFlow alloc] init];
}

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    return YES;
}

-(void)application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls {
    HPAuthParams *receivedAuthParams = nil;
    for (NSURL *url in urls) {
        receivedAuthParams = [self.authFlow handlePostAuthenticateURL:url];
        
        if (receivedAuthParams != nil) {
            break;
        }
    }
    
    if (receivedAuthParams != nil) {
        [self.authFlow handleAuthParams:receivedAuthParams];
    }
}

@end
