import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
import { UINT16_MAX } from "../../../core/binary/UINT16_MAX.js";
import { UINT32_MAX } from "../../../core/binary/UINT32_MAX.js";

/**
 *
 * @param {number} input
 * @param {BinaryDataType} raw_type
 * @param {boolean} normalized
 * @returns {number}
 */
export function decode_attribute_value(input, raw_type, normalized) {
    if (!normalized) {
        return input;
    }

    switch (raw_type) {
        case BinaryDataType.Float32:
        case BinaryDataType.Float64:
            return input;
        case BinaryDataType.Uint16:
            return input / UINT16_MAX;
        case BinaryDataType.Uint32:
            return input / UINT32_MAX;
        default:
            throw new Error(`Unsupported data type ${raw_type}`);
    }
}