// swift-tools-version: 6.0
import PackageDescription

let package = Package(
	name: "MagnumOpusCore",
	// macOS 15+ / iOS 18+ required for Swift 6 strict concurrency + latest SwiftUI APIs
	platforms: [
		.macOS(.v15),
		.iOS(.v18),
	],
	products: [
		.library(name: "Models", targets: ["Models"]),
		.library(name: "MailStore", targets: ["MailStore"]),
		.library(name: "TaskStore", targets: ["TaskStore"]),
		.library(name: "IMAPClient", targets: ["IMAPClient"]),
		.library(name: "SMTPClient", targets: ["SMTPClient"]),
		.library(name: "MIMEParser", targets: ["MIMEParser"]),
		.library(name: "SyncEngine", targets: ["SyncEngine"]),
	],
	dependencies: [
		.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
		.package(url: "https://github.com/apple/swift-nio-imap.git", from: "0.1.0"),
		.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.27.0"),
		.package(url: "https://github.com/groue/GRDB.swift.git", from: "7.0.0"),
	],
	targets: [
		.target(name: "Models"),
		.target(
			name: "MailStore",
			dependencies: [
				"Models",
				.product(name: "GRDB", package: "GRDB.swift"),
			]
		),
		.target(
			name: "IMAPClient",
			dependencies: [
				"Models",
				.product(name: "NIOIMAP", package: "swift-nio-imap"),
				.product(name: "NIOSSL", package: "swift-nio-ssl"),
			]
		),
		.target(
			name: "SMTPClient",
			dependencies: [
				"Models",
				.product(name: "NIO", package: "swift-nio"),
				.product(name: "NIOSSL", package: "swift-nio-ssl"),
			]
		),
		.target(name: "MIMEParser"),
		.target(
			name: "TaskStore",
			dependencies: [
				"Models",
				"MailStore",
				.product(name: "GRDB", package: "GRDB.swift"),
			]
		),
		.target(
			name: "SyncEngine",
			dependencies: ["Models", "IMAPClient", "SMTPClient", "MailStore", "TaskStore"]
		),
		.testTarget(name: "ModelsTests", dependencies: ["Models"]),
		.testTarget(name: "MailStoreTests", dependencies: ["MailStore"]),
		.testTarget(
			name: "IMAPClientTests",
			dependencies: [
				"IMAPClient",
			]
		),
		.testTarget(name: "MIMEParserTests", dependencies: ["MIMEParser"]),
		.testTarget(name: "SMTPClientTests", dependencies: ["SMTPClient", "Models"]),
		.testTarget(name: "TaskStoreTests", dependencies: ["TaskStore", "MailStore"]),
		.testTarget(name: "SyncEngineTests", dependencies: ["SyncEngine", "IMAPClient", "MailStore"]),
	]
)
