use betex_macros::TaggedEnumBridge;
use serde_json::json;

#[derive(Debug, Clone, PartialEq, Eq, TaggedEnumBridge, serde::Serialize, serde::Deserialize)]
enum StructEvent {
    Created { order_id: u64, note: String },
    Updated { status: String },
}

#[test]
fn struct_enum_externally_tagged_shape_and_roundtrip() {
    let event = StructEvent::Created {
        order_id: 42,
        note: "ok".to_string(),
    };

    let tagged: StructEventExternallyTagged = event.clone().into();
    let value = serde_json::to_value(&tagged).expect("serialize externally tagged struct enum");
    assert_eq!(
        value,
        json!({
            "Created": {
                "order_id": 42,
                "note": "ok"
            }
        })
    );

    let decoded_tagged: StructEventExternallyTagged =
        serde_json::from_value(value).expect("deserialize externally tagged struct enum");
    let decoded_event: StructEvent = decoded_tagged.into();
    assert_eq!(decoded_event, event);
}

#[test]
fn struct_enum_untagged_serialization_shape() {
    let event = StructEvent::Updated {
        status: "OPEN".to_string(),
    };

    let untagged: StructEventUntagged = event.clone().into();
    let value = serde_json::to_value(&untagged).expect("serialize untagged struct enum");
    assert_eq!(
        value,
        json!({
            "status": "OPEN"
        })
    );
}
