package kr.gmtc.gw.elastic.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.util.AffineTransformation;

public class CommonUtils {

	private static int ID_SEQ = 0;
	
	
	public static String generateAnalysisID() {
		
		ID_SEQ = (ID_SEQ >= 999) ? 0 : ID_SEQ+1;
		
		String id = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")) + String.format("%03d", ID_SEQ);
		return id;
	}
	
	
	public static String getNow() {
		return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss"));
	}
	
	public static String getNowWithMillsecond() {
		return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss.SSS"));
	}
	
	public static double meterOnWGS84(double meter) {
		return (1 * meter) / 111000;
	}
	
	public static Point rotatePoint(Point pointToRotate, Point rotationCenter, double angleInDegrees) {
		AffineTransformation rotation = AffineTransformation.rotationInstance(
											Math.toRadians(angleInDegrees), rotationCenter.getX(), rotationCenter.getY()
										);
        return (Point) rotation.transform(pointToRotate);
	}
	
	public static Coordinate rotatePoint(Coordinate pointToRotate, Coordinate rotationCenter, double angleInDegrees) {
		//중심점을 기준으로 각도만큼 회전하는 변환을 생성. 양의 각도는 반시계 방향으로의 회전을 나타냄
		AffineTransformation rotation = AffineTransformation.rotationInstance(
	                                        Math.toRadians( -1 * angleInDegrees), rotationCenter.x, rotationCenter.y
	                                    );
	    Coordinate dest = new Coordinate();	    
	    return rotation.transform(pointToRotate, dest);
	}
	
}
