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

/**
 *
 * @param {BinaryDataType} dt
 * @param {number} channel_count
 * @returns {string|THREE.PixelFormatGPU}
 */
export function computeThreeTextureInternalFormatFromDataType(dt, channel_count) {
    let suffix = '';
    switch (dt) {
        case BinaryDataType.Uint8:
            suffix = '8UI';
            break;
        case BinaryDataType.Uint16:
            suffix = '16UI';
            break;
        case BinaryDataType.Uint32:
            suffix = '32UI';
            break;
        case BinaryDataType.Int8:
            suffix = '8I';
            break;
        case BinaryDataType.Int16:
            suffix = '16I';
            break;
        case BinaryDataType.Int32:
            suffix = '32I';
            break;
        case BinaryDataType.Float16:
            suffix = '16F';
            break;
        case BinaryDataType.Float32:
            suffix = '32F';
            break;
        case BinaryDataType.Float64:
            suffix = '64F';
            break;
        default:
            throw new Error(`Unsupported data type '${dt}'`);
    }

    let prefix = '';

    switch (channel_count) {
        case 1:
            prefix = 'R';
            break;
        case 2:
            prefix = 'RG';
            break;
        case 3:
            prefix = 'RGB';
            break;
        case 4:
            prefix = 'RGBA';
            break;
        default:
            throw new Error(`Unsupported channel count '${channel_count}'`);
    }

    return prefix + suffix;
}
