package core.process;

import core.operation.Search;
import core.operation.Select;
import error.GExcptInit;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class C_TeacherSelectStudent extends TempProcess {
    String studentId;
    String teacherId;
    protected static String buttonName ="选择学生";
    protected static String iconURL="";
    protected static String targetURL="/home/teacher-select-student";
    protected static String info = "";

    public void select()throws Exception{
        if(!check()) throw new GExcptInit("ID Attrs init error!");
        Select select=new Select();
        select.setOptions(new HashMap<>());
        select.addOptions("teacher_id",this.getTeacherId());
        select.addOptions("student_id",this.getStudentId());
        Map<String,Object> options=select.execute(null);
    }
    public List<Map<String,String>> search(String studentId) throws Exception{
        Search search  = new Search() ;
        search.setOptions(new HashMap<>());
        search.addOptions("table","student");
        List<String> fields = new ArrayList<>();
        fields.add("*");
        search.addOptions("field",fields);
        Map<String,String> limits = new HashMap<>();
        limits.put("id",studentId);
        search.addOptions("limits",limits);
        search.addOptions("start",0);
        search.addOptions("end",10);
        Map<String, Object> options = search.execute(null);
        List<String[]> result = (List<String[]>) options.get("result");
        List<Map<String,String>> studentsInfo = new ArrayList<>();
        core.process.Utils.formatResult(result, studentsInfo);
        return studentsInfo;
    }
    protected boolean check() {
        if(this.getStudentId()==null||this.getTeacherId()==null)
            return false;
        return true;
    }
    public String getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(String teacherId) {
        this.teacherId = teacherId;
    }

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    @Override
    public String getInfo() {
        return info;
    }

    @Override
    public String getTargetURL() {
        return targetURL;
    }

    @Override
    public String getIconURL() {
        return iconURL;
    }

    @Override
    public String getButtonName() {
        return buttonName;
    }

}
