//
//  NetworkReachibility.swift
//  WOKA
//
//  Created by MacBook Pro on 06/05/24.
//

import Alamofire

class NetworkReachibility{
    
    static let shared = NetworkReachibility()
    private init(){}
    let manager = NetworkReachabilityManager(host: "www.apple.com")
    fileprivate var isInternetReachable = false
    
    func startMonitoring(onCompletion : @escaping (Bool) -> Void) {
        manager?.startListening(onQueue: DispatchQueue.main, onUpdatePerforming: { (status) in
            switch status {
            case .notReachable:
                print("network connection status - lost")
                self.isInternetReachable = false
                onCompletion(false)
            case .reachable(.ethernetOrWiFi):
                print("network connection status - ethernet/WiFI")
                self.isInternetReachable = true
                onCompletion(true)
            case .reachable(.cellular):
                print("network connection status - cellular")
                self.isInternetReachable = true
                onCompletion(true)
            default:
                self.isInternetReachable = false
                onCompletion(false)
                break
            }
        })
    }
    
    func stopMonitoring(){
        manager?.stopListening()
    }
}
