local MAJOR, MINOR = "LibMatic-SoundPack-1.0", 5
assert(LibStub, MAJOR .. " requires LibStub")
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end

local LSM = LibStub("LibSharedMedia-3.0", true)

local DEFAULT_EMBED = "Libs\\LibMatic\\"

lib.sounds = {
    { name = "Batman Punch", file = "BatmanPunch.ogg" },
    { name = "Blast", file = "Blast.ogg" },
    { name = "Blue Portal", file = "BluePortal.ogg" },
    { name = "Boop", file = "Boop.ogg" },
    { name = "Clamps", file = "Clamps.ogg" },
    { name = "Codec", file = "Codec.ogg" },
    { name = "Coin", file = "Coin.ogg" },
    { name = "Combo Breaker", file = "COMBO-BREAKER.ogg" },
    { name = "Done", file = "Done.ogg" },
    { name = "Green Portal", file = "GreenPortal.ogg" },
    { name = "Heaven", file = "Heaven.ogg" },
    { name = "Heroism Cast", file = "Heroism_Cast.ogg" },
    { name = "Jedi Beam", file = "JediBeam.ogg" },
    { name = "Level Up", file = "LevelUp.ogg" },
    { name = "Magic Beam", file = "MagicBeam.ogg" },
    { name = "Shotgun", file = "Shotgun.ogg" },
    { name = "Solid Alert", file = "Solid-Alert.ogg" },
    { name = "Thunder", file = "Thunder.ogg" },
    { name = "Whoop", file = "Whoop.ogg" },
    { name = "Zombie Attack", file = "tn_anom_attack01.ogg" },
    { name = "Azerite Loot", file = "ui_80_azeriteloot_toast.ogg" },
    { name = "Alarm Clock", file = "AlarmClockWarning2.ogg" },
    { name = "Anima Cast", file = "FX_Revendreth_Anima_Controlled_Cast_Medium_Stereo_03.ogg" },
    { name = "Artifact Unlock", file = "UI_70_Artifact_Forge_Trait_Unlock.ogg" },
    { name = "Banshee", file = "FX_Torghast_Sylvanas_Impact_Ghost_Spirit_BansheeVox_01.ogg" },
    { name = "Deathwing Wound", file = "mon_deathwing_wound_02.ogg" },
    { name = "Epic Loot Toast", file = "ui_epicloot_toast_01.ogg" },
    { name = "Icy Touch", file = "deathknight_icytouch.ogg" },
    { name = "Legendary Toast", file = "UI_Legendary_Item_Toast.ogg" },
    { name = "LFG Denied", file = "lfg_denied.ogg" },
    { name = "Mission Complete", file = "ui_garrison_toast_missioncomplete.ogg" },
    { name = "Shop", file = "Shop_2.ogg" },
    { name = "Shop 2", file = "Shop_2-2.ogg" },
    { name = "Low Boom", file = "10.ogg" },
    { name = "Titan Light", file = "FX_TITAN_CLEANSINGLIGHTDEVICE_OPEN_TONAL_STEREO_02.ogg" },
    { name = "World Quest Complete", file = "ui_worldquest_complete.ogg" },
    { name = "Timer Tick", file = "TimerTick.ogg" },
    { name = "Darkmoon Bell", file = "fx_darkmoonfaire_bell.ogg" },
    { name = "Grand Bell", file = "go_9du_skycity_bell_grand01_oneshot_1880890.ogg" },
    { name = "Karazhan Bell Toll", file = "kharazahnbelltoll.ogg" },
    { name = "Chapel Bell", file = "moretrianbell_cast_oneshot_5738550.ogg" },
    { name = "Warning Bell", file = "rtc_80_trogs_attack_warning_bell_sweetener.ogg" },
    { name = "Temple Bell", file = "wow_mop_intro_sfx_bell_nogong_mono.ogg" },
    { name = "Scenario Chime", file = "ui_scenario_stage_end.ogg" },
}

lib.builtins = {
    { name = "Raid Warning", path = "Sound\\Interface\\RaidWarning.ogg" },
}

function lib:GetPath(addon, file, embed)
    embed = embed or DEFAULT_EMBED
    if embed ~= "" and embed:sub(-1) ~= "\\" then embed = embed .. "\\" end
    return "Interface\\AddOns\\" .. addon .. "\\" .. embed .. "LibMatic-SoundPack-1.0\\Sounds\\" .. file
end

function lib:GetBasePath(addon, embed)
    embed = embed or DEFAULT_EMBED
    if embed ~= "" and embed:sub(-1) ~= "\\" then embed = embed .. "\\" end
    return "Interface\\AddOns\\" .. addon .. "\\" .. embed .. "LibMatic-SoundPack-1.0\\Sounds\\"
end

function lib:Register(addon, embed)
    if not LSM then LSM = LibStub("LibSharedMedia-3.0", true) end
    if not LSM or type(addon) ~= "string" or addon == "" then return 0 end
    local count = 0
    for _, entry in ipairs(self.sounds) do
        local path = self:GetPath(addon, entry.file, embed)
        LSM:Register("sound", entry.name, path)
        count = count + 1
        if entry.aliases then
            for _, alias in ipairs(entry.aliases) do
                LSM:Register("sound", alias, path)
                count = count + 1
            end
        end
    end
    for _, b in ipairs(self.builtins) do
        LSM:Register("sound", b.name, b.path)
        count = count + 1
    end
    return count
end
