
package com.lideeyunji.tool.framework.sql.build.build.dql;


import com.lideeyunji.tool.framework.sql.build.ISQLExpression;
import com.lideeyunji.tool.framework.sql.build.buildmodel.SQLInterpretContext;
import com.lideeyunji.tool.framework.sql.build.buildmodel.dql.SqlInfoJoinModel;
import com.lideeyunji.tool.framework.sql.core.model.SqlFormatModel;
import net.sf.jsqlparser.JSQLParserException;
/**
 * left join ,inner join ,right join相关
 */
public class BuildJoin implements ISQLExpression<SqlFormatModel>  {


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

        SqlInfoJoinModel model = context.getJoinModel();
        SqlInfoJoinModel.JoinType joinType = model.getJoinType();
        String onStr = model.getOnStr();
        String tableName = model.getTableName();

        String joinSymbolStr="";
        switch (joinType) {
            case LEFT_JOIN:
                joinSymbolStr = "LEFT JOIN";
                break;
            case RIGHT_JOIN:
                joinSymbolStr = "RIGHT JOIN";
                break;
            case INNER_JOIN:
                joinSymbolStr = "INNER JOIN";
                break;
        }
        String sql= joinSymbolStr+" "+tableName+" on "+onStr;

        SqlFormatModel sqlFormatModel = new SqlFormatModel(sql);
        return sqlFormatModel;
    }



}
