import Foundation

enum AppSettings {
    static let portalURL = URL(string: stringValue("DeliRoutePortalURL", fallback: "https://deliroute.com.au/login?app=1"))!
    static let apiBaseURL = URL(string: stringValue("DeliRouteAPIBaseURL", fallback: "https://deliroute.com.au"))!
    static let releaseVersion = stringValue("DeliRouteReleaseVersion", fallback: "1.0.36")

    private static func stringValue(_ key: String, fallback: String) -> String {
        guard
            let url = Bundle.main.url(forResource: "AppConfig", withExtension: "plist"),
            let data = try? Data(contentsOf: url),
            let plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil),
            let dictionary = plist as? [String: Any],
            let value = dictionary[key] as? String,
            !value.isEmpty
        else {
            return fallback
        }

        return value
    }
}
