import Foundation

/// `Bundle.module` shim for the self-contained CocoaPods build.
///
/// The vendored MapMapKit and valhalla-mobile sources locate their resources
/// (earcon `.wav`s, Valhalla `default.json` / `tzdata.tar`) via SwiftPM's
/// synthesised `Bundle.module`, which does not exist under CocoaPods. The
/// podspec ships those files in a single `resource_bundles` entry named
/// `MapmapNavResources`; the vendoring transform rewrites every
/// `Bundle.module` reference to `MapmapNavResourceBundle.bundle`, resolved
/// here across the layouts a static-framework pod can end up in.
enum MapmapNavResourceBundle {
    private final class Token {}

    static let bundle: Bundle = {
        let owner = Bundle(for: Token.self)
        let candidates: [URL?] = [
            owner.resourceURL,
            owner.bundleURL,
            Bundle.main.resourceURL,
            Bundle.main.bundleURL,
        ]
        for base in candidates {
            if let url = base?.appendingPathComponent("MapmapNavResources.bundle"),
               let found = Bundle(url: url) {
                return found
            }
        }
        // Last resort: the framework/main bundle itself (resources may have
        // been flattened into it).
        return owner
    }()
}
