// Path: sqlsauce-core/src/main/java/space/npstr/sqlsauce/DbUtils.java
// public class DbUtils {
// 
//     private static final Logger log = LoggerFactory.getLogger(DbUtils.class);
// 
//     private DbUtils() {
//     }
// 
//     /**
//      * Build parameters for queries like the true lazy bastard you are.
//      * <p>
//      * Pass pairs of strings and objects, and you'll be fine, various exceptions or logs otherwise.
//      */
//     @CheckReturnValue
//     public static Map<String, Object> paramsOf(Object... stringObjectPairs) {
//         if (stringObjectPairs.length % 2 == 1) {
//             log.warn("Passed an uneven number of args to the parameter factory, this is a likely bug.");
//         }
// 
//         Map<String, Object> result = new HashMap<>();
//         for (int ii = 0; ii < stringObjectPairs.length - 1; ii += 2) {
//             result.put((String) stringObjectPairs[ii], stringObjectPairs[ii + 1]);
//         }
//         return result;
//     }
// 
//     @Nullable
//     public static <T extends Annotation> T getAnnotation(Annotation[] annotations, Class<T> anClass) {
//         for (Annotation annotation : annotations) {
//             if (anClass.isInstance(annotation)) {
//                 @SuppressWarnings("unchecked") T result = (T) annotation;
//                 return result;
//             }
//         }
//         return null;
//     }
// }


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.DynamicParameterizedType;
import space.npstr.sqlsauce.DbUtils;
import javax.annotation.Nullable;
import java.sql.Array;
    public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
            throws SQLException {
        if (value == null) {
            st.setNull(index, sqlTypes()[0]);
        } else {
            if (this.basicType == null) {
                throw new IllegalStateException("Not properly initialized, missing the basic type");
            }

            Connection connection = st.getConnection();
            Array array;

            if (basicType.equals(Integer.class)) {
                @SuppressWarnings("unchecked") Integer[] ints = ((HashSet<Integer>) value).toArray(new Integer[0]);
                array = connection.createArrayOf("integer", ints);
            } else if (basicType.equals(Long.class)) {
                @SuppressWarnings("unchecked") Long[] longs = ((HashSet<Long>) value).toArray(new Long[0]);
                array = connection.createArrayOf("bigint", longs);
            } else if (basicType.equals(String.class)) {
                @SuppressWarnings("unchecked") String[] strings = ((HashSet<String>) value).toArray(new String[0]);
                array = connection.createArrayOf("text", strings);
            } else {
                throw new IllegalArgumentException("Unsupported type: " + basicType.getSimpleName());
            }

            st.setArray(index, array);
        }
    }

    private Class<?> getBasicType(ParameterType reader) {
// Path: sqlsauce-core/src/main/java/space/npstr/sqlsauce/DbUtils.java
// public class DbUtils {
// 
//     private static final Logger log = LoggerFactory.getLogger(DbUtils.class);
// 
//     private DbUtils() {
//     }
// 
//     /**
//      * Build parameters for queries like the true lazy bastard you are.
//      * <p>
//      * Pass pairs of strings and objects, and you'll be fine, various exceptions or logs otherwise.
//      */
//     @CheckReturnValue
//     public static Map<String, Object> paramsOf(Object... stringObjectPairs) {
//         if (stringObjectPairs.length % 2 == 1) {
//             log.warn("Passed an uneven number of args to the parameter factory, this is a likely bug.");
//         }
// 
//         Map<String, Object> result = new HashMap<>();
//         for (int ii = 0; ii < stringObjectPairs.length - 1; ii += 2) {
//             result.put((String) stringObjectPairs[ii], stringObjectPairs[ii + 1]);
//         }
//         return result;
//     }
// 
//     @Nullable
//     public static <T extends Annotation> T getAnnotation(Annotation[] annotations, Class<T> anClass) {
//         for (Annotation annotation : annotations) {
//             if (anClass.isInstance(annotation)) {
//                 @SuppressWarnings("unchecked") T result = (T) annotation;
//                 return result;
//             }
//         }
//         return null;
//     }
// }


// Path: sqlsauce-core/src/main/java/space/npstr/sqlsauce/hibernate/types/HashSetBasicType.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.DynamicParameterizedType;
import space.npstr.sqlsauce.DbUtils;
import javax.annotation.Nullable;
import java.sql.Array;

    public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
            throws SQLException {
        if (value == null) {
            st.setNull(index, sqlTypes()[0]);
        } else {
            if (this.basicType == null) {
                throw new IllegalStateException("Not properly initialized, missing the basic type");
            }

            Connection connection = st.getConnection();
            Array array;

            if (basicType.equals(Integer.class)) {
                @SuppressWarnings("unchecked") Integer[] ints = ((HashSet<Integer>) value).toArray(new Integer[0]);
                array = connection.createArrayOf("integer", ints);
            } else if (basicType.equals(Long.class)) {
                @SuppressWarnings("unchecked") Long[] longs = ((HashSet<Long>) value).toArray(new Long[0]);
                array = connection.createArrayOf("bigint", longs);
            } else if (basicType.equals(String.class)) {
                @SuppressWarnings("unchecked") String[] strings = ((HashSet<String>) value).toArray(new String[0]);
                array = connection.createArrayOf("text", strings);
            } else {
                throw new IllegalArgumentException("Unsupported type: " + basicType.getSimpleName());
            }

            st.setArray(index, array);
        }
    }

    private Class<?> getBasicType(ParameterType reader) {
        BasicType annotation = DbUtils.getAnnotation(reader.getAnnotationsMethod(), BasicType.class);