import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;

public class Main {

    private static String bytesToHex(byte[] bytes) {
        StringBuilder result = new StringBuilder();
        for (byte b : bytes) {
            result.append(String.format("%02x", b));
        }
        return result.toString();
    }

    public static String generateSignature(
            String secret,
            String method,
            String path,
            String body,
            String timestamp
    ) {
        try {
            String message =
                    method + "\n" +
                    path + "\n" +
                    body + "\n" +
                    timestamp + "\n";

            Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
            SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
            sha256_HMAC.init(secret_key);

            return bytesToHex(sha256_HMAC.doFinal(message.getBytes(StandardCharsets.UTF_8)));

        } catch (Exception e) {
            throw new RuntimeException("Error generating signature", e);
        }
    }

    public static void main(String[] args) {

        String secret = "{{YOUR_SECRET_KEY}}";
        String method = "GET";
	// Path should be dynamic here like below
	// api/v1/payout/{{YOUR_ORDER_ID}}/status
        String path = "api/v1/payout/6778MYP412/status";

         
        String body = "[]";  

        String timestamp = String.valueOf(System.currentTimeMillis());

        String signature = generateSignature(secret, method, path, body, timestamp);

        System.out.println("Body: " + body);
        System.out.println("Signature: " + signature);
        System.out.println("Timestamp: " + timestamp);
    }
}
