use libremetaverse::assets::gltf::GltfDocument;
use libremetaverse::assets::{ArchiveConstants, AssetTexture, OarFile};
use libremetaverse::import_export::ModelPrim;
use libremetaverse::materials::LegacyMaterial;
use libremetaverse::messages::linden::AgentDropGroupMessage;
use libremetaverse::packets::UseCircuitCodePacket;
use libremetaverse::{BitPack, PacketFrequency, PermissionMask, Permissions, Primitive};

fn member_id<T>(result: Result<T, libremetaverse::Error>) -> &'static str {
    result
        .err()
        .expect("failure-only shim unexpectedly returned a value")
        .csharp_member()
        .expect("failure-only shim error")
}

#[test]
fn each_wire_data_domain_is_callable_and_failure_only() {
    assert_eq!(
        member_id(UseCircuitCodePacket::new_with_constructor()),
        "M:LibreMetaverse.Packets.UseCircuitCodePacket.#ctor"
    );
    assert_eq!(
        member_id(AgentDropGroupMessage::new()),
        "M:LibreMetaverse.Messages.Linden.AgentDropGroupMessage.#ctor"
    );
    assert_eq!(
        member_id(AssetTexture::new_with_constructor()),
        "M:LibreMetaverse.Assets.AssetTexture.#ctor"
    );
    assert_eq!(
        member_id(Primitive::new_with_constructor()),
        "M:LibreMetaverse.Primitive.#ctor"
    );
    assert_eq!(
        member_id(LegacyMaterial::new_with_constructor()),
        "M:LibreMetaverse.Materials.LegacyMaterial.#ctor"
    );
    assert_eq!(
        member_id(GltfDocument::new()),
        "M:LibreMetaverse.Assets.Gltf.GltfDocument.#ctor"
    );
    assert_eq!(
        member_id(ModelPrim::new()),
        "M:LibreMetaverse.ImportExport.ModelPrim.#ctor"
    );
    assert_eq!(
        member_id(OarFile::package_archive(String::new(), String::new())),
        "M:LibreMetaverse.Assets.OarFile.PackageArchive(System.String,System.String)"
    );
    assert_eq!(
        member_id(BitPack::new(Vec::new(), 0)),
        "M:LibreMetaverse.BitPack.#ctor(System.Byte[],System.Int32)"
    );
    assert_eq!(
        member_id(Permissions::new(0, 0, 0, 0, 0)),
        "M:LibreMetaverse.Permissions.#ctor(System.UInt32,System.UInt32,System.UInt32,System.UInt32,System.UInt32)"
    );
}

#[test]
fn wire_widths_flags_and_constants_match_the_catalog() {
    assert_eq!(PacketFrequency::High as u8, 2);
    assert_eq!(PermissionMask::COPY.0, 32_768);
    assert_eq!(ArchiveConstants::ASSETS_PATH, "assets/");
    assert_eq!(
        libremetaverse::PrimitiveParticleSystem::LEGACY_DATA_BLOCK_SIZE,
        86
    );
}
