import { type IProfile } from "./licelTypes";

/**
* Парсит профиль Licel из строки.
* @param line - Строка, содержащая данные профиля.
* @returns Объект IProfile, содержащий данные профиля.
*/
export function parseLicelProfile(line: string): IProfile {
    const items = line.trim().split(/\s+/);
    const [wavelengthStr, polarization] = items[7]!.split(".");
    return {
        active: items[0] === "1",
        photon: items[1] === "1",
        laserType: parseInt(items[2]!, 10),
        nDataPoints: parseInt(items[3]!, 10),
        reserved: [
            parseInt(items[4]!, 10),
            parseInt(items[8]!, 10),
            parseInt(items[9]!, 10),
        ],
        highVoltage: parseInt(items[5]!, 10),
        binWidth: parseFloat(items[6]!),
        wavelength: parseFloat(wavelengthStr!),
        polarization: polarization!,
        binShift: parseInt(items[10]!, 10),
        decBinShift: parseInt(items[11]!, 10),
        adcBits: parseInt(items[12]!, 10),
        nShots: parseInt(items[13]!, 10),
        discrLevel: parseFloat(items[14]!),
        deviceId: items[15]!.slice(0, 2),
        nCrate: parseInt(items[15]!.slice(2), 10),
        data: new Uint32Array([]),
    };
}
