//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//

import Foundation
import XCTest

@testable import SignalServiceKit

final class OWSOutgoingResendResponseTest: SSKBaseTest {
    func testStableDecoding() throws {
        let serializedValue = try XCTUnwrap(Data(base64Encoded: "YnBsaXN0MDDUAQIDBAUGjY5YJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QGAcIS0xNTk9QUVVbXGNpbXBzen6BgoOEhVUkbnVsbN8QIQkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSlZzb3J0SWRfEBVoYXNMZWdhY3lNZXNzYWdlU3RhdGVeaXNWb2ljZU1lc3NhZ2VdZGlkQXBwZW5kU0tETV8QEmxlZ2FjeU1lc3NhZ2VTdGF0ZV8QD2V4cGlyZVN0YXJ0ZWRBdF51bmlxdWVUaHJlYWRJZFlleHBpcmVzQXRfEBFpc0dyb3VwU3RvcnlSZXBseV8QEWlzVmlld09uY2VNZXNzYWdlXxASZGVyaXZlZENvbnRlbnRIaW50XxATcmVjZWl2ZWRBdFRpbWVzdGFtcF8QEndhc1JlbW90ZWx5RGVsZXRlZF8QEmlzVmlld09uY2VDb21wbGV0ZV8QE2hhc1N5bmNlZFRyYW5zY3JpcHRYdW5pcXVlSWRdYXR0YWNobWVudElkc18QD29yaWdpbmFsR3JvdXBJZFYkY2xhc3NfEA9NVExNb2RlbFZlcnNpb25fEBxzdG9yZWRTaG91bGRTdGFydEV4cGlyZVRpbWVyXxAUd2FzTm90Q3JlYXRlZExvY2FsbHlfEBZyZWNpcGllbnRBZGRyZXNzU3RhdGVzXxAQb3JpZ2luYWxUaHJlYWRJZF8QHG91dGdvaW5nTWVzc2FnZVNjaGVtYVZlcnNpb25fEBhvcmlnaW5hbE1lc3NhZ2VQbGFpbnRleHRfEBBncm91cE1ldGFNZXNzYWdlXxASc3RvcmVkTWVzc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lc2VuZFJlc3BvbnNlXxARVFNPdXRnb2luZ01lc3NhZ2VZVFNNZXNzYWdlXVRTSW50ZXJhY3Rpb25ZQmFzZU1vZGVsXxATVFNZYXBEYXRhYmFzZU9iamVjdF8QD05TS2V5ZWRBcmNoaXZlctGPkFRyb290gAEACAARABoAIwAtADIANwBSAFgAnQCkALwAywDZAO4BAAEPARkBLQFBAVYBbAGBAZYBrAG1AcMB1QHcAe4CDQIkAj0CUAJvAooCnQKyAsUC2gLoAvIC/AL+AwADAgMEAwYDCAMKAwwDDgMQAxIDFAMWAxgDGgMcAx4DIAMiAyQDJgMoAyoDLAMuAzADMgM0AzYDOAM6AzwDPgNAA0EDaANqA3MDmgOfA6oDqwOtA7IDuwPGA8kD0QPaA/0EBAQMBA4EEAQSBBQEFgQdBCkEPgRABEIERARJBFYEaQRrBHAEcwR6BH8EggSqBLMEuQTFBMcEyQTLBM0E0gTWBPgFAQUGBQkFFgVGBaEFowWsBbEFugXWBeoF9AYCBgwGIgY0BjcGPAAAAAAAAAIBAAAAAAAAAJEAAAAAAAAAAAAAAAAAAAY+"))
        let resendResponse = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(ofClass: OWSOutgoingResendResponse.self, from: serializedValue))
        XCTAssertEqual(
            resendResponse.originalMessagePlaintext?.base64EncodedString(),
            "ClYKA0FCQzIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4gMyJ44MyYAB6JAogAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAQ==",
        )
        XCTAssertEqual(
            resendResponse.originalThreadId,
            "gd/rq8//fR4RzhvN3G9KcKlQoj7cguQFjTOqLV6JUSbo=",
        )
        XCTAssertEqual(
            resendResponse.originalGroupId?.base64EncodedString(),
            "d/rq8//fR4RzhvN3G9KcKlQoj7cguQFjTOqLV6JUSbo=",
        )
        XCTAssertEqual(resendResponse.contentHint, .resendable)
        XCTAssertEqual(resendResponse.didAppendSKDM, false)
        XCTAssertEqual(resendResponse.uniqueId, "00000000-0000-4000-8000-00000000000B")
        XCTAssertEqual(resendResponse.uniqueThreadId, "00000000-0000-4000-8000-00000000000A")
    }
}
