-- Rack & Ruin shared card texture library
-- Provides texture path lookups for all card game addons (Blackjack, Poker, etc.)

RackAndRuin = RackAndRuin or {}

local CARD_PATH = "Interface\\AddOns\\RackAndRuin\\Textures\\RackAndRuin\\"

RackAndRuin.RANKS = { "A","2","3","4","5","6","7","8","9","10","J","Q","K" }
RackAndRuin.SUITS = { "S","H","D","C" } -- Spades, Hearts, Diamonds, Clubs

RackAndRuin.SUIT_NAMES = {
    S = "Spades",
    H = "Hearts",
    D = "Diamonds",
    C = "Clubs",
}

-- Returns the texture path for a given rank + suit code, e.g. GetCardTexture("A", "S")
function RackAndRuin.GetCardTexture(rank, suit)
    if not rank or not suit then return nil end
    return CARD_PATH .. tostring(rank) .. tostring(suit) .. ".png"
end

-- Returns the texture path for the card back
function RackAndRuin.GetCardBackTexture()
    return CARD_PATH .. "CardBack.png"
end

-- Builds a full 52-card deck as a table of {rank=, suit=, texture=} entries
function RackAndRuin.BuildDeck()
    local deck = {}
    for _, suit in ipairs(RackAndRuin.SUITS) do
        for _, rank in ipairs(RackAndRuin.RANKS) do
            table.insert(deck, {
                rank = rank,
                suit = suit,
                texture = RackAndRuin.GetCardTexture(rank, suit),
            })
        end
    end
    return deck
end

-- Fisher-Yates shuffle helper
function RackAndRuin.Shuffle(deck)
    for i = #deck, 2, -1 do
        local j = math.random(i)
        deck[i], deck[j] = deck[j], deck[i]
    end
    return deck
end

-- Example usage (in your Blackjack/Poker addon):
-- local deck = RackAndRuin.Shuffle(RackAndRuin.BuildDeck())
-- local card = table.remove(deck)
-- myCardFrame.texture:SetTexture(card.texture)
-- backFrame.texture:SetTexture(RackAndRuin.GetCardBackTexture())
