// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "UserpilotCapacitor",
    // Matches UserpilotCapacitor.podspec's `s.ios.deployment_target = '13.0'`
    // and the Userpilot iOS SDK's own floor, so CocoaPods and SwiftPM consumers
    // get the same minimum. Keep the two in step whenever either moves.
    //
    // 13, not 14: a Capacitor 6 app generates `platform :ios, '13.0'` and
    // `platforms: [.iOS(.v13)]`, so a 14.0 floor made CocoaPods refuse the pod
    // outright ("required a higher minimum deployment target") and would make
    // SwiftPM reject the package. Verified by running the sample app on
    // Capacitor 6, 7 and 8 over both dependency managers.
    //
    // Deliberately NOT .v15. Capacitor 8's binary is built minos 15.0, but
    // capacitor-swift-pm declares no `platforms:` floor of its own, so a
    // Capacitor 8 app — already on iOS 15 — links fine against a lower package,
    // while Capacitor 6/7 consumers keep working.
    platforms: [.iOS(.v13)],
    products: [
        .library(
            name: "UserpilotCapacitor",
            targets: ["UserpilotPlugin"])
    ],
    dependencies: [
        // A range, not `from:`. `from: "7.0.0"` means ">=7.0.0 <8.0.0", which
        // is what locked SwiftPM consumers out of Capacitor 8. capacitor-swift-pm
        // ships 6.x, 7.x and 8.x tags all exposing the same Capacitor + Cordova
        // products, so one range serves every Capacitor major this plugin
        // supports and SwiftPM resolves to whichever the host app is on.
        .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", "6.0.0"..<"9.0.0"),
        // Without this the target's `import Userpilot` is unresolvable and no
        // SwiftPM consumer can build the plugin — before it was added, only
        // CocoaPods pinned the native SDK.
        //
        // `exact:` on purpose, not a range: this must stay in lockstep with
        // `s.dependency "Userpilot", "1.4.0"` in UserpilotCapacitor.podspec, or
        // CocoaPods and SwiftPM consumers silently get different native SDKs.
        // Both move together, or neither does — see native-parity.mdc.
        .package(url: "https://github.com/Userpilot/ios-sdk.git", exact: "1.4.0")
    ],
    targets: [
        .target(
            name: "UserpilotPlugin",
            dependencies: [
                .product(name: "Capacitor", package: "capacitor-swift-pm"),
                .product(name: "Cordova", package: "capacitor-swift-pm"),
                .product(name: "Userpilot", package: "ios-sdk")
            ],
            path: "ios/Sources/UserpilotPlugin"),
        .testTarget(
            name: "UserpilotPluginTests",
            dependencies: ["UserpilotPlugin"],
            path: "ios/Tests/UserpilotPluginTests")
    ]
)
