import NIOIMAPCore

struct IMAPCommandRunner {
	private let connection: IMAPConnection
	private var tagCounter: Int = 0

	init(connection: IMAPConnection) {
		self.connection = connection
	}

	mutating func nextTag() -> String {
		tagCounter += 1
		return "A\(tagCounter)"
	}

	mutating func run(_ command: Command) async throws -> [Response] {
		let tag = nextTag()
		let tagged = TaggedCommand(tag: tag, command: command)
		return try await connection.sendCommand(tag, command: .tagged(tagged))
	}
}
