package dao.impl;

import common.DBTool;
import dao.TeacherDB;
import pojo.TeacherInfo;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class TeacherDBImpl implements TeacherDB {
    @Override
    public ArrayList<TeacherInfo> getAllTeacherInfo() {
        ArrayList<TeacherInfo> teacherInfos = new ArrayList<>();
        String sql = "select * from t_teacher";
        try{
            PreparedStatement ps = DBTool.getPreparedStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                TeacherInfo teacherInfo = new TeacherInfo();
                teacherInfo.setId(rs.getInt("N_TEACHER_ID"));
                teacherInfo.setName(rs.getString("VC_TEACHER_NAME"));
                teacherInfo.setSex(rs.getInt("N_SEX"));
                teacherInfo.setBrith(rs.getString("VC_BIRTH"));
                teacherInfo.setEduc(rs.getInt("N_EDUC"));
                teacherInfo.setTitle(rs.getInt("N_TITLE"));
                teacherInfos.add(teacherInfo);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return teacherInfos;
    }

    @Override
    public TeacherInfo getTeacherInfoByID(int id) {
        return null;
    }

    @Override
    public TeacherInfo getTeacherInfoByName(String name) {
        return null;
    }

    @Override
    public int addTeacherInfo(TeacherInfo teacherInfo) {
        return 0;
    }

    @Override
    public int updateTeacherInfo(TeacherInfo teacherInfo) {
        return 0;
    }

    @Override
    public int deleteTeacherInfo(int id) {
        return 0;
    }
}
