//! Stable built-in viewer sound identifiers from the pinned C# source.

use libremetaverse_types::UUID;
use std::collections::HashMap;

const SOUNDS: &[(&str, &str)] = &[
    ("BELL_TING", "ed124764-705d-d497-167a-182cd9fa2e6c"),
    ("CLICK", "4c8c3c77-de8d-bde2-b9b8-32635e0fd4a6"),
    (
        "HEALTH_REDUCTION_FEMALE",
        "219c5d93-6c09-31c5-fb3f-c5fe7495c115",
    ),
    (
        "HEALTH_REDUCTION_MALE",
        "e057c244-5768-1056-c37e-1537454eeb62",
    ),
    ("IM_START", "c825dfbc-9827-7e02-6507-3713d18916c1"),
    (
        "INSTANT_MESSAGE_NOTIFICATION",
        "67cc2844-00f3-2b3c-b991-6418d01e1bb7",
    ),
    ("INVALID_OPERATION", "4174f859-0d3d-c517-c424-72923dc21f65"),
    ("KEYBOARD_LOOP", "5e191c7b-8996-9ced-a177-b2ac32bfea06"),
    (
        "MONEY_REDUCTION_COINS",
        "77a018af-098e-c037-51a6-178f05877c6f",
    ),
    (
        "MONEY_INCREASE_CASH_REGISTER_BELL",
        "104974e3-dfda-428b-99ee-b0d4e748d3a3",
    ),
    ("NULL_KEYSTROKE", "2ca849ba-2885-4bc3-90ef-d4987a5b983a"),
    ("OBJECT_COLLISION", "be582e5d-b123-41a2-a150-454c39e961c8"),
    (
        "OBJECT_COLLISION_RUBBER",
        "212b6d1e-8d9c-4986-b3aa-f3c6df8d987d",
    ),
    (
        "OBJECT_COLLISION_PLASTIC",
        "d55c7f3c-e1c3-4ddc-9eff-9ef805d9190e",
    ),
    (
        "OBJECT_COLLISION_FLESH",
        "2d8c6f51-149e-4e23-8413-93a379b42b67",
    ),
    (
        "OBJECT_COLLISION_WOOD_SPLINTERING",
        "6f00669f-15e0-4793-a63e-c03f62fee43a",
    ),
    (
        "OBJECT_COLLISION_GLASS_BREAK",
        "85cda060-b393-48e6-81c8-2cfdfb275351",
    ),
    (
        "OBJECT_COLLISION_METAL_CLUNK",
        "d1375446-1c4d-470b-9135-30132433b678",
    ),
    (
        "OBJECT_CREATE_WHOOSH",
        "3c8fc726-1fd6-862d-fa01-16c5b2568db6",
    ),
    (
        "OBJECT_DELETE_SHAKE",
        "0cb7b00a-4c10-6948-84de-a93c09af2ba9",
    ),
    ("OBJECT_REZ", "f4a0660f-5446-dea2-80b7-6482a082803c"),
    (
        "PIE_MENU_APPEAR_DING",
        "8eaed61f-92ff-6485-de83-4dcc938a478e",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT",
        "d9f73cf8-17b4-6f7a-1565-7951226c305d",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT1",
        "f6ba9816-dcaf-f755-7b67-51b31b6233e5",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT2",
        "7aff2265-d05b-8b72-63c7-dbf96dc2f21f",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT3",
        "09b2184e-8601-44e2-afbb-ce37434b8ba1",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT4",
        "bbe4c7fc-7044-b05e-7b89-36924a67593c",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT5",
        "d166039b-b4f5-c2ec-4911-c85c727b016c",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT6",
        "242af82b-43c2-9a3b-e108-3b0c7e384981",
    ),
    (
        "PIE_MENU_SLICE_HIGHLIGHT7",
        "c1f334fb-a5be-8fe7-22b3-29631c21cf0b",
    ),
    ("SNAPSHOT", "3d09f582-3851-c0e0-f5ba-277ac5c73fb4"),
    (
        "TELEPORT_TEXTURE_APPLY",
        "d7a9a565-a013-2a69-797d-5332baa1a947",
    ),
    ("THUNDER", "e95c96a5-293c-bb7a-57ad-ce2e785ad85f"),
    ("WINDOW_CLOSE", "2c346eda-b60c-ab33-1119-b8941916a499"),
    ("WINDOW_OPEN", "c80260ba-41fd-8a46-768a-6bf236360e3a"),
    ("ZIPPER", "6cf2be26-90cb-2669-a599-f5ab7698225f"),
];

pub(crate) fn sound(name: &str) -> UUID {
    let value = SOUNDS
        .iter()
        .find_map(|(candidate, value)| (*candidate == name).then_some(*value))
        .unwrap_or_else(|| panic!("unknown built-in sound {name}"));
    UUID::new_with_string(value.to_owned()).expect("built-in sound UUID is valid")
}

pub(crate) fn sounds() -> HashMap<UUID, String> {
    SOUNDS
        .iter()
        .map(|(name, _)| (sound(name), (*name).to_owned()))
        .collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn sound_catalog_is_complete_and_unique() {
        let catalog = sounds();
        assert_eq!(catalog.len(), SOUNDS.len());
        assert_eq!(catalog[&sound("BELL_TING")], "BELL_TING");
        assert_eq!(catalog[&sound("ZIPPER")], "ZIPPER");
    }
}
