package it.integry.integrywmsnative.core.utility;

import com.annimon.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class UtilityDB {

    public static String valueToString(Object value) {
        String valueString;

        if (value == null) {
            valueString = "NULL";
        } else {

            valueString = value.toString();

            if(value instanceof String) {
                if(UtilityString.isNullOrEmpty((String) value)){
                    valueString = "NULL";
                } else {
                    valueString = "'" + valueString.replaceAll("'","''") + "'";
                }
            } else if (value instanceof Date){

                valueString = "'" + UtilityDate.formatDate((Date) value, UtilityDate.COMMONS_DATE_FORMATS.YMD_DASH) + "'";
            } else if (value instanceof Integer) {

            } else {
                valueString = null;
            }
        }
        return valueString;
    }

    public static String listValueToString(List<String> lista) {
        lista = Stream.of(lista).map(UtilityDB::valueToString).toList();
        return StringUtils.join(lista,",");
    }

}
