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

import com.jeelowcode.framework.plus.build.ISQLExpression;
import com.jeelowcode.framework.plus.build.build.dql.BuildJoin;
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;

/**
 * @author JX
 * @create 2024-07-04 9:14
 * @dedescription:
 */
public class SqlInfoJoinModel<T> extends SqlInfoBaseModel {

    private String tableName;
    private JoinType joinType;
    private String onStr;

    public static Builder builder(){
        return new Builder();
    }

    public static class Builder{
        private SqlInfoJoinModel joinModel = new SqlInfoJoinModel();

        //构建having
        public Builder joinTable(String tableName,String alias){
            joinModel.setTableName(tableName+" "+alias);
            return this;
        }
        public Builder innerJoin(){
            joinModel.joinType= JoinType.INNER_JOIN;
            return this;
        }
        public Builder leftJoin(){
            joinModel.joinType= JoinType.LEFT_JOIN;
            return this;
        }
        public Builder rightJoin(){
            joinModel.joinType= JoinType.RIGHT_JOIN;
            return this;
        }
        public Builder on(String leftStr,String rightStr){
            joinModel.onStr=leftStr+" = "+rightStr;
            return this;
        }
        public SqlInfoJoinModel<SqlFormatModel> build(){
            ISQLExpression<SqlFormatModel> expression = new BuildJoin();
            joinModel.setSqlExpression(expression);
            return joinModel;
        }
    }

    public enum JoinType{
        LEFT_JOIN,
        RIGHT_JOIN,
        INNER_JOIN
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public JoinType getJoinType() {
        return joinType;
    }

    public void setJoinType(JoinType joinType) {
        this.joinType = joinType;
    }

    public String getOnStr() {
        return onStr;
    }

    public void setOnStr(String onStr) {
        this.onStr = onStr;
    }
}
