"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPointsFromNested = void 0;
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ramda_1 = require("ramda");
var helpers_1 = require("./helpers");
var getPointsFromNested = function (metadata, entities) {
    if (entities === void 0) { entities = []; }
    return (0, ramda_1.pipe)((0, ramda_1.chain)(function (entity) {
        var entityType = (0, mdm_sdk_1.getEntityType)(metadata, entity.type);
        return ((entityType === null || entityType === void 0 ? void 0 : entityType.geoLocationAttributes) || []).flatMap(function (geoAttr) {
            if ((0, mdm_sdk_1.findAttributeTypeByUri)(metadata, geoAttr.latitude, entity.type) &&
                (0, mdm_sdk_1.findAttributeTypeByUri)(metadata, geoAttr.longitude, entity.type)) {
                var points = (0, helpers_1.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)
                        }
                    });
                });
            }
        });
    }), (0, ramda_1.filter)(ramda_1.identity), (0, ramda_1.uniqBy)((0, ramda_1.prop)('id')))(entities);
};
exports.getPointsFromNested = getPointsFromNested;
