// Exact Rust translations of LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs.
// Source SHA-256: f1e2a14f9671d6af084d72cc5280daf372985bf1b08c75e5989d9c8df0932a64

use libremetaverse::{
    GridClient, Inventory, InventoryAttachment, InventoryObject, InventoryTexture,
    InventoryWearable,
};
use libremetaverse_types::{AssetType, AttachmentPoint, UUID, WearableType};
use std::sync::Arc;

fn store() -> Inventory {
    Inventory::new_with_grid_client_uuid(
        Arc::new(GridClient::new().unwrap()),
        UUID::random().unwrap(),
    )
    .unwrap()
}

fn texture_link(target: UUID) -> InventoryTexture {
    let mut item = InventoryTexture::new(UUID::random().unwrap()).unwrap();
    item.base.set_asset_type(AssetType::Link);
    item.base.set_asset_uuid(target);
    item
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.IsLink_TextureItemWithLinkAssetType_ReturnsTrue::test b85452466c0fdc47a44cc08166f93a660bbf466b0e2205910c1ea84fee22896c translated
#[test]
fn is_link_texture_item_with_link_asset_type_returns_true() {
    let item = texture_link(UUID::random().unwrap());
    assert!(item.base.is_link().unwrap());
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.IsLink_NormalTexture_ReturnsFalse::test 8c08505d6e89c4395115dbb060529419755aa1a81ca8889804ea00e6f94bf534 translated
#[test]
fn is_link_normal_texture_returns_false() {
    let mut item = InventoryTexture::new(UUID::random().unwrap()).unwrap();
    item.base.set_asset_type(AssetType::Texture);
    item.base.set_asset_uuid(UUID::random().unwrap());
    assert!(!item.base.is_link().unwrap());
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.ResolvedItemID_OnMisclassifiedTextureLink_ReturnsAssetUUID::test cad5b5fb10523254ff19b7842b0e48984bc75182a26bc897f165a43770bb47f4 translated
#[test]
fn resolved_item_id_on_misclassified_texture_link_returns_asset_uuid() {
    let target = UUID::random().unwrap();
    let item = texture_link(target);
    assert_eq!(item.base.resolved_item_id(), target);
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.InventoryStore_Contains_FindsTargetByResolvedItemID::test 3c1f8596462c3a9e229c84ea44e44728bf175e1a0e8213ae92d1b02b08320b0b translated
#[test]
fn inventory_store_contains_finds_target_by_resolved_item_id() {
    let store = store();
    let target_id = UUID::random().unwrap();
    let mut target = InventoryWearable::new(target_id).unwrap();
    target.set_wearable_type(WearableType::Shirt);
    target.base.set_asset_type(AssetType::Clothing);
    target.base.set_asset_uuid(UUID::random().unwrap());
    store.update_node_for(&target).unwrap();
    let link = texture_link(target_id);
    assert!(
        store
            .contains_with_uuid(link.base.resolved_item_id())
            .unwrap()
    );
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.InventoryStore_Indexer_ReturnsWearable_WhenTargetIsWearable::test c7ce0b860743cfa5225de4322c8d7bf95094296b1dd2d07fd273bbd4e81a9fcf translated
#[test]
fn inventory_store_indexer_returns_wearable_when_target_is_wearable() {
    let store = store();
    let target_id = UUID::random().unwrap();
    let mut target = InventoryWearable::new(target_id).unwrap();
    target.set_wearable_type(WearableType::Shirt);
    target.base.set_asset_type(AssetType::Clothing);
    target.base.set_asset_uuid(UUID::random().unwrap());
    target.base.base.set_name("Test Shirt".into());
    store.update_node_for(&target).unwrap();
    let link = texture_link(target_id);
    let resolved = store
        .get_value_or_default_with_uuid_a7c63fbe::<InventoryWearable>(link.base.resolved_item_id())
        .unwrap();
    assert!(
        resolved.is_some(),
        "target must retain its InventoryWearable type"
    );
    assert_eq!(resolved.unwrap().wearable_type(), WearableType::Shirt);
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.InventoryStore_Indexer_ReturnsAttachment_WhenTargetIsAttachment::test f58debff8f66b7b417215eb6879f96935647b66cc619fdb00e6815c9ce5e7c67 translated
#[test]
fn inventory_store_indexer_returns_attachment_when_target_is_attachment() {
    let store = store();
    let target_id = UUID::random().unwrap();
    let mut target = InventoryAttachment::new(target_id).unwrap();
    target.set_attachment_point(AttachmentPoint::Chest);
    target.base.set_asset_type(AssetType::Object);
    target.base.set_asset_uuid(UUID::random().unwrap());
    target.base.base.set_name("Test Attachment".into());
    store.update_node_for(&target).unwrap();
    let link = texture_link(target_id);
    let resolved = store
        .get_value_or_default_with_uuid_a7c63fbe::<InventoryAttachment>(
            link.base.resolved_item_id(),
        )
        .unwrap();
    assert!(
        resolved.is_some(),
        "target must retain its InventoryAttachment type"
    );
    assert_eq!(resolved.unwrap().attachment_point(), AttachmentPoint::Chest);
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.InventoryStore_Indexer_ReturnsObject_WhenTargetIsObject::test b8137c994019103977b0b85d8c148e12ae8f9051334ca487db7c88bcbe707d40 translated
#[test]
fn inventory_store_indexer_returns_object_when_target_is_object() {
    let store = store();
    let target_id = UUID::random().unwrap();
    let mut target = InventoryObject::new(target_id).unwrap();
    target.set_attach_point(AttachmentPoint::RightHand);
    target.base.set_asset_type(AssetType::Object);
    target.base.set_asset_uuid(UUID::random().unwrap());
    target.base.base.set_name("Test Object".into());
    store.update_node_for(&target).unwrap();
    let link = texture_link(target_id);
    let resolved = store
        .get_value_or_default_with_uuid_a7c63fbe::<InventoryObject>(link.base.resolved_item_id())
        .unwrap();
    assert!(
        resolved.is_some(),
        "target must retain its InventoryObject type"
    );
    assert_eq!(resolved.unwrap().attach_point(), AttachmentPoint::RightHand);
}

// parity-case: LibreMetaverse.Tests/MisclassifiedLinkRegressionTests.cs::MisclassifiedLinkRegressionTests.InventoryStore_NotContains_WhenTargetAbsent::test 6900e220c33ec135d02c55e047c7052a095d5dd9d71da4a857ae70bc151c472b translated
#[test]
fn inventory_store_not_contains_when_target_absent() {
    let store = store();
    let link = texture_link(UUID::random().unwrap());
    assert!(
        !store
            .contains_with_uuid(link.base.resolved_item_id())
            .unwrap()
    );
}
