import Testing
@testable import MagnumOpus

@Suite("APIClient")
struct APIClientTests {
	@Test("decodes thread list from JSON")
	func decodesThreadList() throws {
		let json = """
		{
			"threads": [
				{
					"threadId": "t001",
					"subject": "Q1 Planning",
					"authors": "Alice, Bob",
					"totalMessages": 3,
					"tags": "inbox,unread",
					"timestamp": 1709884532,
					"accountId": "personal"
				}
			]
		}
		""".data(using: .utf8)!

		let response = try JSONDecoder().decode(ThreadListResponse.self, from: json)
		#expect(response.threads.count == 1)
		#expect(response.threads[0].subject == "Q1 Planning")
	}

	@Test("decodes message list from JSON")
	func decodesMessageList() throws {
		let json = """
		{
			"messages": [
				{
					"messageId": "msg001@example.com",
					"threadId": "t001",
					"fromHeader": "Alice <alice@example.com>",
					"toHeader": "user@example.com",
					"subject": "Q1 Planning",
					"date": "2024-03-08T10:15:32+01:00",
					"inReplyTo": "",
					"body": "Hey, let's plan Q1.",
					"tags": "inbox,unread",
					"timestamp": 1709884532,
					"accountId": "personal"
				}
			]
		}
		""".data(using: .utf8)!

		let response = try JSONDecoder().decode(MessageListResponse.self, from: json)
		#expect(response.messages.count == 1)
		#expect(response.messages[0].body == "Hey, let's plan Q1.")
	}
}
