local MAJOR, MINOR = "LibMatic-SoundPack-1.0", 3
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", aliases = { "Combo Breaker" } },
    { name = "Done", file = "Done.ogg" },
    { name = "GreenPortal", file = "GreenPortal.ogg", aliases = { "Green Portal" } },
    { name = "Heaven", file = "Heaven.ogg" },
    { name = "Heroism Cast", file = "Heroism_Cast.ogg" },
    { name = "Jedi Beam :Details", file = "JediBeam.ogg", aliases = { "Jedi Beam" } },
    { 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 = "Anomaly 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 = "Ten", file = "10.ogg" },
    { name = "Titan Light", file = "FX_TITAN_CLEANSINGLIGHTDEVICE_OPEN_TONAL_STEREO_02.ogg" },
    { name = "World Quest Complete", file = "ui_worldquest_complete.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
