package dao;

import utils.Utils;

import java.util.Map;

public class Insert extends SQLStmt {
    private static final String fs ="INSERT INTO ";
    private Map<String, String> vMap;
    Insert(String table, Map<String, String> vMap){
        super(table);
        this.setVMap(vMap);
    }
    @Override
    public String getSQL() {
        return this.getFs()+this.getVs();
    }

    @Override
    public String getFs() {
        return fs+this.getTable()+" ";
    }
    private String getVs(){
        StringBuilder sql = new StringBuilder("(");
        for(String key: this.getVMap().keySet()){
            sql.append(key).append(", ");
        }
        sql = new StringBuilder(Utils.cutTail(sql.toString(), 2) + ") ");
        sql.append("VALUES (\'");
        for(String value: vMap.values()){
            sql.append(value).append("\', \'");
        }
        sql = new StringBuilder(Utils.cutTail(sql.toString(), 3) + ")");
        return sql.toString();
    }
    private Map<String, String> getVMap() {
        return vMap;
    }

    private void setVMap(Map<String, String> vMap) {
        this.vMap = vMap;
    }
}
