local maskCollection,waveManager

local stages = {}


stages.TYPE = {
    I_PIECE = 1,
    THE_SLOPE = 2,
    CHAMBERS = 3,
    ALPS = 4,
    T_PIECE = 5,
    OFFICE = 6,
    MORAY_TOWERS = 7,
    HEART = 8,
}


stages.typeData = {
    [stages.TYPE.I_PIECE] = {
        layerName = "(Mask Collection) (Stage) I-Piece",
    },
    [stages.TYPE.THE_SLOPE] = {
        layerName = "(Mask Collection) (Stage) The Slope",
    },
    [stages.TYPE.CHAMBERS] = {
        layerName = "(Mask Collection) (Stage) Chambers",
    },
    [stages.TYPE.ALPS] = {
        layerName = "(Mask Collection) (Stage) Alps",
    },
    [stages.TYPE.T_PIECE] = {
        layerName = "(Mask Collection) (Stage) T-Piece",
    },
    [stages.TYPE.OFFICE] = {
        layerName = "(Mask Collection) (Stage) Office",
    },
    [stages.TYPE.MORAY_TOWERS] = {
        layerName = "(Mask Collection) (Stage) Moray Towers",
    },
    [stages.TYPE.HEART] = {
        layerName = "(Mask Collection) (Stage) Heart",
    },
}


function stages.pickStageType(difficulty,lastStageType)
    local stageTypes = stages.availableStageTypes[difficulty]
    local lastStageTypeIndex = table.ifind(stageTypes,lastStageType)

    if lastStageTypeIndex == nil or #stageTypes <= 1 then
        return RNG.irandomEntry(stageTypes)
    end

    local randomIndex = RNG.randomInt(1,#stageTypes - 1)

    if randomIndex >= lastStageTypeIndex then
        return stageTypes[randomIndex + 1]
    else
        return stageTypes[randomIndex]
    end
end


function stages.onInitAPI()
    maskCollection = require("maskCollection/scripts/maskCollection")
    waveManager = require("maskCollection/scripts/waveManager")

    stages.availableStageTypes = {
        [waveManager.WAVE_DIFFICULTY.BEGINNING] = {
            stages.TYPE.I_PIECE,
        },
        [waveManager.WAVE_DIFFICULTY.EASY] = {
            stages.TYPE.I_PIECE,
            stages.TYPE.THE_SLOPE,
            stages.TYPE.CHAMBERS,
        },
        [waveManager.WAVE_DIFFICULTY.MEDIUM] = {
            stages.TYPE.ALPS,
            stages.TYPE.T_PIECE,
        },
        [waveManager.WAVE_DIFFICULTY.HARD] = {
            stages.TYPE.OFFICE,
            stages.TYPE.MORAY_TOWERS,
            stages.TYPE.HEART,
        },
        [waveManager.WAVE_DIFFICULTY.SPICY] = {
            stages.TYPE.I_PIECE,
            stages.TYPE.THE_SLOPE,
            stages.TYPE.CHAMBERS,
            stages.TYPE.ALPS,
            stages.TYPE.T_PIECE,
            stages.TYPE.OFFICE,
            stages.TYPE.MORAY_TOWERS,
            stages.TYPE.HEART,
        },
    }
end


return stages