use crate::signaling::{decode_signaling, encode_signaling};
use crate::types::SignalingMessage;

#[test]
fn offer_roundtrip() {
    let message = SignalingMessage::Offer {
        sdp: "v=0\r\no=- 1 1 IN IP4 127.0.0.1".to_string(),
    };
    let encoded = encode_signaling(&message);
    let decoded = decode_signaling(&encoded).unwrap();
    assert_eq!(message, decoded);
}

#[test]
fn answer_roundtrip() {
    let message = SignalingMessage::Answer {
        sdp: "v=0\r\no=- 2 2 IN IP4 127.0.0.1".to_string(),
    };
    let encoded = encode_signaling(&message);
    let decoded = decode_signaling(&encoded).unwrap();
    assert_eq!(message, decoded);
}

#[test]
fn candidate_roundtrip() {
    let message = SignalingMessage::IceCandidate {
        candidate: "candidate:1".to_string(),
        sdp_mid: Some("audio".to_string()),
        sdp_mline_index: Some(0),
    };
    let encoded = encode_signaling(&message);
    let decoded = decode_signaling(&encoded).unwrap();
    assert_eq!(message, decoded);
}

#[test]
fn invalid_candidate_rejected() {
    let payload = "{\"type\":\"ice_candidate\",\"candidate\":\"\"}";
    let result = decode_signaling(payload);
    assert!(result.is_err());
}

#[test]
fn unknown_type_rejected() {
    let payload = "{\"type\":\"unknown\"}";
    let result = decode_signaling(payload);
    assert!(result.is_err());
}
