import XCTest
@testable import FchatiApp

final class MessageStoreModelTests: XCTestCase {
    func testMessageRoundTripPreservesAttachmentAndReadStatus() throws {
        let message = ChatMessage(
            id: "message-id",
            from: "peer-id",
            fromName: "Alex",
            body: "Shared a file: photo.jpg",
            sentAt: Date(timeIntervalSince1970: 1_721_995_200),
            attachment: AttachmentInfo(fileID: "file-id", name: "photo.jpg", size: 128),
            isRead: false
        )

        let encoder = JSONEncoder()
        encoder.dateEncodingStrategy = .iso8601
        let decoder = JSONDecoder()
        decoder.dateDecodingStrategy = .iso8601
        let encodedMessage = try encoder.encode(message)
        let decodedMessage = try decoder.decode(ChatMessage.self, from: encodedMessage)

        XCTAssertEqual(decodedMessage.id, message.id)
        XCTAssertEqual(decodedMessage.attachment, message.attachment)
        XCTAssertEqual(decodedMessage.isRead, message.isRead)
    }
}
