package dao;

import java.util.List;
import java.util.Map;

public class Select extends SQLStmt {
    private static final String fs ="SELECT ";
    private Map<String,String> limits;
    private List<String> columns;
    private int startRow;
    private int endRow;
    public Select(List<String> columns, String table, Map<String,String> limits, int startRow, int endRow){
        super(table);
        this.setColumns(columns);
        this.setLimits(limits);
        this.setStartRow(startRow);
        this.setEndRow(endRow);
    }
    @Override
    public String getSQL() {
        return this.getFs()+this.getTs()+this.getLs();
    }
    private String getLs(){
        String sql = dao.Utils.whereAnd(this.getLimits())+" ";
        sql+="LIMIT "+this.getStartRow()+", "+this.getEndRow();
        return sql;
    }
    @Override
    public String getFs() {
        return fs+dao.Utils.linkColumn(this.getColumns())+" ";
    }
    private String getTs(){
        return "FROM "+this.getTable()+" ";
    }
    private Map<String, String> getLimits() {
        return limits;
    }
    public void setLimits(Map<String, String> limits) {
        this.limits = limits;
    }
    private List<String> getColumns() {
        return columns;
    }
    public void setColumns(List<String> columns) {
        this.columns = columns;
    }
    private int getStartRow() {
        return startRow;
    }

    private void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    private int getEndRow() {
        return endRow;
    }

    private void setEndRow(int endRow) {
        this.endRow = endRow;
    }
}
