#include <srtp2/srtp.h>
#include <iostream>
#include <cstring>

int main() {
    std::cout << "Starting SRTP test example...\n";

    srtp_t session;
    srtp_policy_t policy;
    uint32_t ssrc = 0x12345678; // example SSRC
    
    // Example key (30 bytes: 16 for key + 14 for salt)
    uint8_t key[30] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
                       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
                       0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};

    std::cout << "Initializing SRTP library...\n";
    srtp_err_status_t status = srtp_init();
    if (status != srtp_err_status_ok) {
        std::cerr << "Error: srtp_init failed with status " << status << "\n";
        return 1;
    }
    std::cout << "SRTP initialized successfully\n";

    // Set up policy
    std::cout << "Setting up SRTP policy...\n";
    memset(&policy, 0, sizeof(srtp_policy_t));
    srtp_crypto_policy_set_rtp_default(&policy.rtp);
    srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
    policy.ssrc.type = ssrc_specific;
    policy.ssrc.value = ssrc;
    policy.key = key;
    policy.window_size = 128;
    policy.allow_repeat_tx = 0;
    policy.next = NULL;

    std::cout << "Creating SRTP session...\n";
    status = srtp_create(&session, &policy);
    if (status != srtp_err_status_ok) {
        std::cerr << "Error: srtp_create failed with status " << status << "\n";
        srtp_shutdown();
        return 1;
    }
    std::cout << "SRTP session created successfully\n";

    // Cleanup
    std::cout << "Cleaning up SRTP session...\n";
    status = srtp_dealloc(session);
    if (status != srtp_err_status_ok) {
        std::cerr << "Warning: srtp_dealloc returned status " << status << "\n";
    }

    std::cout << "Shutting down SRTP library...\n";
    status = srtp_shutdown();
    if (status != srtp_err_status_ok) {
        std::cerr << "Warning: srtp_shutdown returned status " << status << "\n";
    }

    std::cout << "SRTP test completed successfully\n";
    return 0;
}