// swift-tools-version: 6.0
//
// VoiceCatCore — the shared Swift core for the VoiceCat macOS (AppKit) and iOS (SwiftUI)
// clients. It wraps libvoicecat's C ABI (core/include/voicecat.h) as imported through the
// VoiceCatCore.xcframework binary target's module map (`import VoiceCatC`), and exposes a
// Swift-idiomatic, @MainActor-safe surface.
//
// Architecture: docs/architecture.md §4 ("one core, many faces"). The Windows C# client
// (clients/windows/VoiceCat.Interop) is the proven mirror of this same layering — the Swift
// wrapper follows the same patterns (callback-lifetime, string-lifetime, event-delivery
// thread handoff, immediate vc_free_* on list reads) adapted to Swift's interop model.
//
// The XCFramework is a LOCAL BUILD ARTIFACT — run `scripts/build-xcframework.sh` before
// `swift build` / `swift test`. See clients/apple/README.md.
import PackageDescription

let package = Package(
    name: "VoiceCatCore",
    // macOS 14 (Sonoma) is the AppKit client's deployment target. iOS 18 is the SwiftUI client
    // target (clients/apple/iOS/) — 18.0 unlocks the newest AVAudioSession APIs (stereo capture,
    // polar patterns, data sources). Run `scripts/build-xcframework.sh --all` to produce all
    // three slices: macos-arm64, ios-arm64, ios-arm64-simulator.
    // swift-tools-version 6.0 is required for .iOS(.v18); swiftLanguageVersions .v5 keeps the
    // Swift 5 language mode (avoids Swift 6 strict concurrency checking on pre-existing code).
    platforms: [
        .macOS(.v14),
        .iOS(.v18),
    ],
    products: [
        .library(name: "VoiceCatCore", targets: ["VoiceCatCore"]),
    ],
    targets: [
        // Binary target — the prebuilt static lib + headers + module map. Produced by
        // scripts/build-xcframework.sh from the `apple-dev` CMake preset.
        .binaryTarget(
            name: "VoiceCatCoreXCF",
            path: "VoiceCatCore.xcframework"
        ),
        // The Swift wrapper library — what the macOS/iOS apps import as `import VoiceCatCore`.
        .target(
            name: "VoiceCatCore",
            dependencies: ["VoiceCatCoreXCF"],
            path: "Sources/VoiceCatCore",
            // Event-cue WAVs (shared with the Windows client) bundled into the package's
            // resource bundle; EventFeedback loads them via Bundle.module. Copied from
            // assets/sounds/ into Sources/VoiceCatCore/Sounds/.
            resources: [.process("Sounds")]
        ),
        // Smoke tests against a real voicecat-server — mirrors clients/windows/
        // VoiceCat.Interop.Tests/VoiceCatClientSmokeTests.cs. Requires the `dev` CMake preset
        // to be built (build/dev/bin/voicecat-server + voicecat-admin).
        //
        // linkerSettings: libvoicecat.a is a static C++20 library (built by the apple-dev
        // preset with vcpkg's clang), so the final executable must link libc++ (the LLVM C++
        // standard library on macOS). vcpkg's static deps (mbedtls/sodium/opus/protobuf/
        // sqlite3/spdlog/asio) are already compiled into the .a; macOS system frameworks
        // (CoreAudio/CoreFoundation) are auto-discovered by the linker (PROGRESS.md).
        .testTarget(
            name: "VoiceCatCoreTests",
            dependencies: ["VoiceCatCore"],
            path: "Tests/VoiceCatCoreTests",
            linkerSettings: [
                .linkedLibrary("c++"),
            ]
        ),
    ],
    swiftLanguageModes: [.v5]
)
