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


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

import java.util.ArrayList;
import java.util.List;

/**
 * @author JX
 * @create 2024-07-04 9:14
 * @dedescription:
 */

public class SqlInfoOrderModel<T> extends SqlInfoBaseModel {

    private List<OrderByModel> orderByList=new ArrayList<>();

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

    public static class OrderByModel{

        public String[] columns;//列

        public boolean asc;//是否是asc 升序

        public void setColumns(String ... columns){
            this.columns = columns;
        }

        public boolean isAsc() {
            return asc;
        }

        public void setAsc(boolean asc) {
            this.asc = asc;
        }

        public String[] getColumns() {
            return columns;
        }
    }


    public static class Builder{
        private SqlInfoOrderModel infoOrderModel = new SqlInfoOrderModel();

        //升序
        public Builder setOrderByAsc(String ... columns){
            OrderByModel model=new OrderByModel();
            model.setAsc(true);
            model.setColumns(columns);
            infoOrderModel.orderByList.add(model);
            return this;
        }

        //降序
        public Builder setOrderByDesc(String ... columns ){
            OrderByModel model=new OrderByModel();
            model.setAsc(false);
            model.setColumns(columns);
            infoOrderModel.orderByList.add(model);
            return this;
        }

        public SqlInfoOrderModel<BuildOrderBy> build(){
            ISQLExpression<SqlFormatModel> expression = new BuildOrderBy();
            infoOrderModel.setSqlExpression(expression);
            return infoOrderModel;
        }
    }

    public List<OrderByModel> getOrderByList() {
        return orderByList;
    }

    public void setOrderByList(List<OrderByModel> orderByList) {
        this.orderByList = orderByList;
    }
}
