
package com.jeelowcode.framework.plus.build.build.dql;

import com.jeelowcode.framework.plus.build.ISQLExpression;
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoGroupModel;
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
import net.sf.jsqlparser.JSQLParserException;

import java.util.Arrays;

/**
 * group  by
 */
public class BuildGroupBy implements ISQLExpression<SqlFormatModel>  {



    @Override
    public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {

        SqlInfoGroupModel sqlInfo = context.getGroupModel();
        String[] columns = sqlInfo.getColumns();

        JeeLowCodeQueryWrapper wrapper=new JeeLowCodeQueryWrapper();
        wrapper.groupBy(Arrays.asList(columns));
        String groupByStr = wrapper.getCustomSqlSegment();

        return new SqlFormatModel(groupByStr);
    }



}
