local ____exports = {}
local OBJECT_NAME
local ____SerializationBrand = require("enums.private.SerializationBrand")
local SerializationBrand = ____SerializationBrand.SerializationBrand
local ____isaacAPIClass = require("functions.isaacAPIClass")
local isaacAPIClassEquals = ____isaacAPIClass.isaacAPIClassEquals
local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
local ____random = require("functions.random")
local getRandom = ____random.getRandom
local ____rng = require("functions.rng")
local isRNG = ____rng.isRNG
local newRNG = ____rng.newRNG
local ____table = require("functions.table")
local copyUserdataValuesToTable = ____table.copyUserdataValuesToTable
local getNumbersFromTable = ____table.getNumbersFromTable
local tableHasKeys = ____table.tableHasKeys
local ____types = require("functions.types")
local isTable = ____types.isTable
local ____utils = require("functions.utils")
local assertDefined = ____utils.assertDefined
--- Helper function to check if something is an instantiated `KColor` object.
function ____exports.isKColor(self, object)
    return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
end
OBJECT_NAME = "KColor"
local KEYS = {"Red", "Green", "Blue", "Alpha"}
--- Helper function to copy a `KColor` Isaac API class.
function ____exports.copyKColor(self, kColor)
    if not ____exports.isKColor(nil, kColor) then
        error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
    end
    return KColor(kColor.Red, kColor.Green, kColor.Blue, kColor.Alpha)
end
--- Helper function to convert a `SerializedKColor` object to a normal `KColor` object. (This is used
-- by the save data manager when reading data from the "save#.dat" file.)
function ____exports.deserializeKColor(self, kColor)
    if not isTable(nil, kColor) then
        error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
    end
    local r, g, b, a = table.unpack(getNumbersFromTable(
        nil,
        kColor,
        OBJECT_NAME,
        table.unpack(KEYS)
    ))
    assertDefined(nil, r, ("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object did not have a value for: Red")
    assertDefined(nil, g, ("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object did not have a value for: Green")
    assertDefined(nil, b, ("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object did not have a value for: Blue")
    assertDefined(nil, a, ("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object did not have a value for: Alpha")
    return KColor(r, g, b, a)
end
--- Helper function to get a random `KColor` object (for use in fonts).
-- 
-- If you want to generate an unseeded object, you must explicitly pass `undefined` to the
-- `seedOrRNG` parameter.
-- 
-- @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
-- `RNG.Next` method will be called. If `undefined` is provided, it will default to
-- a random seed.
-- @param alpha Optional. The alpha value to use. Default is 1.
function ____exports.getRandomKColor(self, seedOrRNG, alpha)
    if alpha == nil then
        alpha = 1
    end
    local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
    local r = getRandom(nil, rng)
    local g = getRandom(nil, rng)
    local b = getRandom(nil, rng)
    return KColor(r, g, b, alpha)
end
--- Used to determine is the given table is a serialized `KColor` object created by the `deepCopy`
-- function.
function ____exports.isSerializedKColor(self, object)
    if not isTable(nil, object) then
        return false
    end
    return tableHasKeys(
        nil,
        object,
        table.unpack(KEYS)
    ) and object[SerializationBrand.K_COLOR] ~= nil
end
function ____exports.kColorEquals(self, kColor1, kColor2)
    return isaacAPIClassEquals(nil, kColor1, kColor2, KEYS)
end
--- Helper function to convert a `KColor` object to a `SerializedKColor` object. (This is used by the
-- save data manager when writing data from the "save#.dat" file.)
function ____exports.serializeKColor(self, kColor)
    if not ____exports.isKColor(nil, kColor) then
        error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
    end
    local kColorTable = {}
    copyUserdataValuesToTable(nil, kColor, KEYS, kColorTable)
    kColorTable[SerializationBrand.K_COLOR] = ""
    return kColorTable
end
return ____exports
