package io.wealthwizards.appsynctesting.utils.transform;

import com.google.gson.GsonBuilder;
import io.wealthwizards.appsynctesting.utils.dynamodb.FieldNamingStrategy;

import java.util.Map;

public final class Transform {
    public String toDynamoDBFilterExpression(Object filter) {
        try {
            @SuppressWarnings("unchecked")
            var entries = (((Map<String, Object>) filter)).entrySet();

            var tree = ExpressionsTree.fromEntries(entries, ":");

            var filterExpression = tree.getFilterExpression();

            return new GsonBuilder()
                    .setFieldNamingStrategy(new FieldNamingStrategy())
                    .create()
                    .toJson(filterExpression);
        } catch (Exception e) {
            return null;
        }
    }
}
