local MAJOR, MINOR = "LibMatic-SoundPack-1.0", 2
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" },
}

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
