// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "MacSync",
    platforms: [
        .macOS(.v13)
    ],
    dependencies: [
        .package(path: "../../@packages/@swift/@macos/agent-core"),
        .package(path: "../../@packages/@swift/@macos/menu-bar"),
        .package(path: "../../@packages/@swift/@macos/sync-framework"),
        .package(path: "../../@packages/@swift/@foundations/logging"),
        .package(path: "../../@packages/@swift/@foundations/settings"),
        .package(path: "../../@packages/@tray/tray-resources"),
        .package(url: "https://github.com/groue/GRDB.swift.git", from: "6.24.0"),
        .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.9.0"),
        .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"),
        .package(url: "https://github.com/httpswift/swifter.git", from: "1.5.0"),
    ],
    targets: [
        // MARK: Shared infrastructure
        .target(
            name: "MacSyncShared",
            dependencies: [
                .product(name: "LilithAgentCore", package: "agent-core"),
                .product(name: "LilithMenuBar", package: "menu-bar"),
                .product(name: "LilithSyncFramework", package: "sync-framework"),
                .product(name: "LilithLogging", package: "logging"),
                .product(name: "LilithSettings", package: "settings"),
                .product(name: "LilithTrayResources", package: "tray-resources"),
                .product(name: "Alamofire", package: "Alamofire"),
                .product(name: "SwiftyJSON", package: "SwiftyJSON"),
                .product(name: "Swifter", package: "swifter"),
            ],
            path: "@packages/shared/Sources/MacSyncShared",
            linkerSettings: [
                .linkedFramework("Contacts"),
                .linkedFramework("Photos"),
                .linkedFramework("EventKit"),
                .linkedFramework("ScriptingBridge"),
            ]
        ),

        // MARK: iMessage module
        .target(
            name: "IMessageSync",
            dependencies: [
                "MacSyncShared",
                .product(name: "GRDB", package: "GRDB.swift"),
            ],
            path: "@packages/imessage/Sources/IMessageSync"
        ),

        // MARK: iPhoto module
        .target(
            name: "IPhotoSync",
            dependencies: [
                "MacSyncShared",
                .product(name: "GRDB", package: "GRDB.swift"),
            ],
            path: "@packages/iphoto/Sources/IPhotoSync"
        ),

        // MARK: iMail module
        .target(
            name: "IMailSync",
            dependencies: ["MacSyncShared"],
            path: "@packages/imail/Sources/IMailSync",
            linkerSettings: [
                .linkedFramework("ScriptingBridge"),
            ]
        ),

        // MARK: iCal module
        .target(
            name: "ICalSync",
            dependencies: ["MacSyncShared"],
            path: "@packages/ical/Sources/ICalSync",
            linkerSettings: [
                .linkedFramework("EventKit"),
            ]
        ),

        // MARK: iReminders module
        .target(
            name: "IReminderSync",
            dependencies: ["MacSyncShared"],
            path: "@packages/ireminders/Sources/IReminderSync",
            linkerSettings: [
                .linkedFramework("EventKit"),
            ]
        ),

        // MARK: iNotes module
        .target(
            name: "INoteSync",
            dependencies: ["MacSyncShared"],
            path: "@packages/inotes/Sources/INoteSync"
        ),

        // MARK: Pure-function contacts core (no Contacts framework — fully testable on Linux/CI)
        .target(
            name: "ContactsSyncCore",
            dependencies: [],
            path: "@packages/contacts-sync-core/Sources/ContactsSyncCore"
        ),

        // MARK: App executable
        .executableTarget(
            name: "MacSyncApp",
            dependencies: [
                "MacSyncShared",
                "ContactsSyncCore",
                "IMessageSync",
                "IPhotoSync",
                "IMailSync",
                "ICalSync",
                "IReminderSync",
                "INoteSync",
            ],
            path: "src/client",
            exclude: ["Resources"]
        ),

        // MARK: Tests
        .testTarget(
            name: "MacSyncSharedTests",
            dependencies: ["MacSyncShared"],
            path: "@packages/shared/Tests/MacSyncSharedTests"
        ),
        .testTarget(
            name: "IMessageSyncTests",
            dependencies: ["IMessageSync"],
            path: "@packages/imessage/Tests/IMessageSyncTests"
        ),

        // MARK: iPhoto Tests
        .testTarget(
            name: "IPhotoSyncTests",
            dependencies: ["IPhotoSync"],
            path: "@packages/iphoto/Tests/IPhotoSyncTests"
        ),

        // MARK: iMail Tests
        .testTarget(
            name: "IMailSyncTests",
            dependencies: ["IMailSync"],
            path: "@packages/imail/Tests/IMailSyncTests"
        ),

        // MARK: iCal Tests
        .testTarget(
            name: "ICalSyncTests",
            dependencies: ["ICalSync"],
            path: "@packages/ical/Tests/ICalSyncTests"
        ),

        // MARK: iReminders Tests
        .testTarget(
            name: "IReminderSyncTests",
            dependencies: ["IReminderSync"],
            path: "@packages/ireminders/Tests/IReminderSyncTests"
        ),

        // MARK: iNotes Tests
        .testTarget(
            name: "INoteSyncTests",
            dependencies: ["INoteSync", "MacSyncShared"],
            path: "@packages/inotes/Tests/INoteSyncTests"
        ),

        // MARK: ContactsSyncCore Tests (pure functions — no Contacts framework required)
        .testTarget(
            name: "ContactsSyncCoreTests",
            dependencies: ["ContactsSyncCore"],
            path: "@packages/contacts-sync-core/Tests/ContactsSyncCoreTests"
        ),
    ]
)
