import PenNavUI
import UIKit

class PenguinNavigator {
    private var config: PenguinModel

    init(config: PenguinModel) {
        self.config = config
    }

    private func logError(_ message: String) {
        // Centralized logging function
        print("PenguinSDKNavigator Error: \(message)")
    }

    func navigateToPOI( referenceId:String,completion: @escaping (Bool, String?) -> Void) {
        PenNavUIManager.shared.getToken(clientID: config.clientID, clientKey: config.clientKey) { [weak self] token, error in

            if let error = error {
                let errorMessage = "Token error while getting the for Navigate to method"
                completion(false, "Failed to get token: \(errorMessage)")

                print("Failed to get token: \(errorMessage)")
                return
            }

            guard let token = token else {
                completion(false, "Token is nil")
                print("Token is nil")
                return
            }
            print("Token Generated")
            print(token);

          
        }
    }

    private func handleNavigation(referenceId: String, token: String, completion: @escaping (Bool, String?) -> Void) {
        DispatchQueue.main.async {
            PenNavUIManager.shared.setToken(token: token)

            PenNavUIManager.shared.navigate(to: referenceId) { [weak self] _, navError in
                guard let self = self else { return }

                if let navError = navError {
                    self.logError("Navigation error: Reference ID invalid")
                    completion(false, "Navigation error: \(navError.localizedDescription)")
                    return
                }

                // Navigation successful
                completion(true, nil)
            }
        }
    }
}
