import Foundation
import Testing
@testable import IMessageSync

@Suite("Outbox send pacing + channel normalization")
struct OutboxSendTests {
    @Test("pacedDelaySeconds spans the range deterministically")
    func pacedDelayBounds() {
        let range: ClosedRange<Double> = 20...90
        #expect(OutboxSendManager.pacedDelaySeconds(range) { 0.0 } == 20)
        #expect(OutboxSendManager.pacedDelaySeconds(range) { 1.0 } == 90)
        #expect(OutboxSendManager.pacedDelaySeconds(range) { 0.5 } == 55)
    }

    @Test("pacedDelaySeconds stays within the range for any rand in [0,1]")
    func pacedDelayWithinRange() {
        let range: ClosedRange<Double> = 20...90
        for r in stride(from: 0.0, through: 1.0, by: 0.1) {
            let d = OutboxSendManager.pacedDelaySeconds(range) { r }
            #expect(d >= range.lowerBound && d <= range.upperBound)
        }
    }

    @Test("normalizeChannel maps Messages service labels to server enum")
    func channelNormalization() {
        #expect(SendService.normalizeChannel("iMessage") == "imessage")
        #expect(SendService.normalizeChannel("SMS") == "sms")
        #expect(SendService.normalizeChannel("imessage") == "imessage")
        #expect(SendService.normalizeChannel("sms") == "sms")
        #expect(SendService.normalizeChannel("carrier-x") == nil)
        #expect(SendService.normalizeChannel("") == nil)
    }
}
