#![allow(dead_code, reason = "schema-hash fixture types whose presence IS the test; variants/fields exist for #[derive(WireFrameHash)] input only")]

use maat_sdk::WireFrameHash;
use maat_sdk_derive::WireFrameHash;

#[derive(WireFrameHash)]
enum Frame1 {
    A,
    B { x: u32 },
}

#[derive(WireFrameHash)]
enum Frame2 {
    A,
    B { x: u32 },
}

#[derive(WireFrameHash)]
enum Frame3 {
    A,
    B { x: u64 }, // x type changed
}

#[derive(WireFrameHash)]
enum Frame4 {
    A,
    B { y: u32 }, // x renamed to y
}

#[derive(WireFrameHash)]
enum Frame5 {
    B { x: u32 }, // variant order swapped
    A,
}

#[derive(WireFrameHash)]
struct StructFrame {
    foo: u32,
    bar: String,
}

#[test]
fn identical_definitions_have_identical_hashes() {
    assert_eq!(Frame1::SCHEMA_HASH, Frame2::SCHEMA_HASH);
}

#[test]
fn different_field_types_change_hash() {
    assert_ne!(Frame1::SCHEMA_HASH, Frame3::SCHEMA_HASH);
}

#[test]
fn renaming_a_field_changes_hash() {
    assert_ne!(Frame1::SCHEMA_HASH, Frame4::SCHEMA_HASH);
}

#[test]
fn variant_order_changes_hash() {
    // Postcard's positional encoding makes order significant — so the hash
    // must reflect order.
    assert_ne!(Frame1::SCHEMA_HASH, Frame5::SCHEMA_HASH);
}

#[test]
fn struct_derive_works() {
    // Compile-time check: derive succeeded and produced a hash const.
    let _: u64 = StructFrame::SCHEMA_HASH;
}

#[test]
fn hashes_are_deterministic_across_runs() {
    // const evaluation guarantees this; this test just exercises the const.
    let h1 = Frame1::SCHEMA_HASH;
    let h2 = Frame1::SCHEMA_HASH;
    assert_eq!(h1, h2);
}
