// Path: src/main/java/com/indoqa/solr/spatial/corridor/wkt/WktUtils.java
// public class WktUtils {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(WktUtils.class);
// 
//     private static final GeometryFactory geometryFactory = new GeometryFactory();
// 
//     public static LineString parseLineString(String corridorLineString) {
//         String rawCoordinates = StringUtils.substringBetween(corridorLineString, "LINESTRING(", ")");
//         if (rawCoordinates == null || rawCoordinates.trim().isEmpty()) {
//             LOGGER.warn("Linestring without coordinates found: '{}'", corridorLineString);
//             return geometryFactory.createLineString((Coordinate[]) null);
//         }
//         String[] coordinates = rawCoordinates.trim().split(",");
// 
//         Coordinate[] wktCoordinates = Arrays.stream(coordinates).map(WktUtils::createCoordinate).toArray(Coordinate[]::new);
//         return geometryFactory.createLineString(wktCoordinates);
//     }
// 
//     public static Point parsePoint(String pointString) {
//         String rawPoints = StringUtils.substringBetween(pointString, "POINT(", ")");
//         if (rawPoints == null) {
//             throw new IllegalArgumentException("Parameter must be a valid WKT Point!");
//         }
// 
//         Coordinate coordinate = createCoordinate(rawPoints);
//         return geometryFactory.createPoint(coordinate);
//     }
// 
//     private static Coordinate createCoordinate(String rawCoordinates) {
//         String[] points = rawCoordinates.trim().split(" ");
// 
//         Coordinate coordinate = new Coordinate();
//         coordinate.x = Double.parseDouble(points[0]);
//         coordinate.y = Double.parseDouble(points[1]);
//         geometryFactory.getPrecisionModel().makePrecise(coordinate);
//         return coordinate;
//     }
// }


import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.CaffeineSpec;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.indoqa.solr.spatial.corridor.wkt.WktUtils;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.concurrent.TimeUnit;
            if (cached != null) {
                return cached;
            }
        }

        String key = calculateHash(value);
        return cache.get(key, s -> parseWktLinestring(value));
    }

    public static HashGeometry cacheLineStringGetHashGeometry(String linestring, int radiusInMeters){
        if(linestring == null){
            return null;
        }
        String key = calculateHash(linestring);
        LineString parsedLineString = parseWktLinestring(linestring);

        cache.put(key, parsedLineString);
        HashGeometry result = new HashGeometry();
        // meters /((PI/180)x6378137)
        result.setGeometry(parsedLineString.buffer(radiusInMeters / (Math.PI / 180 * 6378137)).toText());
        result.setHash(key);
        return result;
    }

    public static void purgeCache() {
        cache.invalidateAll();
        cache.cleanUp();
    }

    private static LineString parseWktLinestring(String corridorLineString) {
// Path: src/main/java/com/indoqa/solr/spatial/corridor/wkt/WktUtils.java
// public class WktUtils {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(WktUtils.class);
// 
//     private static final GeometryFactory geometryFactory = new GeometryFactory();
// 
//     public static LineString parseLineString(String corridorLineString) {
//         String rawCoordinates = StringUtils.substringBetween(corridorLineString, "LINESTRING(", ")");
//         if (rawCoordinates == null || rawCoordinates.trim().isEmpty()) {
//             LOGGER.warn("Linestring without coordinates found: '{}'", corridorLineString);
//             return geometryFactory.createLineString((Coordinate[]) null);
//         }
//         String[] coordinates = rawCoordinates.trim().split(",");
// 
//         Coordinate[] wktCoordinates = Arrays.stream(coordinates).map(WktUtils::createCoordinate).toArray(Coordinate[]::new);
//         return geometryFactory.createLineString(wktCoordinates);
//     }
// 
//     public static Point parsePoint(String pointString) {
//         String rawPoints = StringUtils.substringBetween(pointString, "POINT(", ")");
//         if (rawPoints == null) {
//             throw new IllegalArgumentException("Parameter must be a valid WKT Point!");
//         }
// 
//         Coordinate coordinate = createCoordinate(rawPoints);
//         return geometryFactory.createPoint(coordinate);
//     }
// 
//     private static Coordinate createCoordinate(String rawCoordinates) {
//         String[] points = rawCoordinates.trim().split(" ");
// 
//         Coordinate coordinate = new Coordinate();
//         coordinate.x = Double.parseDouble(points[0]);
//         coordinate.y = Double.parseDouble(points[1]);
//         geometryFactory.getPrecisionModel().makePrecise(coordinate);
//         return coordinate;
//     }
// }


// Path: src/main/java/com/indoqa/solr/spatial/corridor/LineStringUtils.java
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.CaffeineSpec;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.indoqa.solr.spatial.corridor.wkt.WktUtils;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.concurrent.TimeUnit;

            if (cached != null) {
                return cached;
            }
        }

        String key = calculateHash(value);
        return cache.get(key, s -> parseWktLinestring(value));
    }

    public static HashGeometry cacheLineStringGetHashGeometry(String linestring, int radiusInMeters){
        if(linestring == null){
            return null;
        }
        String key = calculateHash(linestring);
        LineString parsedLineString = parseWktLinestring(linestring);

        cache.put(key, parsedLineString);
        HashGeometry result = new HashGeometry();
        // meters /((PI/180)x6378137)
        result.setGeometry(parsedLineString.buffer(radiusInMeters / (Math.PI / 180 * 6378137)).toText());
        result.setHash(key);
        return result;
    }

    public static void purgeCache() {
        cache.invalidateAll();
        cache.cleanUp();
    }

    private static LineString parseWktLinestring(String corridorLineString) {
        return WktUtils.parseLineString(corridorLineString);