import * as Types from "../../../../../types/world/worldTypes";

export default function arrayLinesToObject(array: Array<Types.Line>) {
    if (!Array.isArray(array)) {
        return [];
    }

    return array.map((lineArray) => {
        if (!Array.isArray(lineArray)) {
            return null;
        }

        // Extract common properties from the first point
        const commonLayer = lineArray[0][2];
        const commonType = lineArray[0][3];

        // Map points into a structured format
        const line = lineArray.map(([position, uuid]) => ({
            position,
            uuid,
        }));

        // Create the final structured object
        return {
            layer: commonLayer,
            type: commonType,
            line,
        };
    }).filter((item) => item !== null); // Filter out invalid entries
}
