import Foundation
import Testing
@testable import 康康

struct HealthExportDialogueTests {
    @Test func dialogueTranscriptKeepsTurnOrderAndRoles() {
        let turns: [HealthExportDialogueTurn] = [
            .user("我最近头晕,帮我看看"),
            .assistant("我会结合你的指标和日记整理。"),
            .user("重点看血压")
        ]

        let transcript = HealthExportDialogueTurn.transcript(from: turns)

        #expect(transcript.contains("患者: 我最近头晕,帮我看看"))
        #expect(transcript.contains("康康: 我会结合你的指标和日记整理。"))
        #expect(transcript.contains("患者: 重点看血压"))
        #expect(transcript.range(of: "患者: 我最近头晕")!.lowerBound < transcript.range(of: "患者: 重点看血压")!.lowerBound)
    }

    @Test func dialogueTranscriptDropsEmptyTurns() {
        let turns: [HealthExportDialogueTurn] = [
            .user("  "),
            .assistant("请补充想看的问题"),
            .user("\n最近三个月\n")
        ]

        let transcript = HealthExportDialogueTurn.transcript(from: turns)

        #expect(!transcript.contains("患者:   "))
        #expect(transcript.contains("康康: 请补充想看的问题"))
        #expect(transcript.contains("患者: 最近三个月"))
    }
}
