import { findAttributeTypeByUri, getEntityType } from '@reltio/mdm-sdk';
import { chain, filter, identity, pipe, prop, uniqBy } from 'ramda';
import { getPointsFromAttributes } from './helpers';
export var getPointsFromNested = function (metadata, entities) {
    if (entities === void 0) { entities = []; }
    return pipe(chain(function (entity) {
        var entityType = getEntityType(metadata, entity.type);
        return ((entityType === null || entityType === void 0 ? void 0 : entityType.geoLocationAttributes) || []).flatMap(function (geoAttr) {
            if (findAttributeTypeByUri(metadata, geoAttr.latitude, entity.type) &&
                findAttributeTypeByUri(metadata, geoAttr.longitude, entity.type)) {
                var points = getPointsFromAttributes(metadata, entity, geoAttr);
                return points === null || points === void 0 ? void 0 : points.map(function (_a) {
                    var lat = _a.lat, lng = _a.lng;
                    return ({
                        id: "".concat(entity.uri, "_nested_").concat(lat, "_").concat(lng),
                        entity: entity,
                        label: entity.label,
                        point: {
                            lat: Number(lat),
                            lng: Number(lng)
                        }
                    });
                });
            }
        });
    }), filter(identity), uniqBy(prop('id')))(entities);
};
