package com.yuyu.srdisassemble.data;

import com.yuyu.srdisassemble.data.mapper.SqlDataMapper;
import com.yuyu.srdisassemble.pojo.DisassembleData;
import com.yuyu.srdisassemble.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 峰。
 * @version 1.0
 * @project SrDisassemble
 * @date 2024/6/17 16:57:26
 * @description
 */
public class SqlData {
    /**
     * 插件启动时加载表
     */
    public static void initTable(){
        SqlSession sqlSession = MybatisUtil.getSqlSession();
//        sqlSession.getConfiguration().addMapper(SqlDataMapper.class);
        SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);

        mapper.createTable();
        mapper.setChartseUtf8();

        sqlSession.commit();
        sqlSession.close();
    }

    /**
     * 新增数据
     * @param data
     */
    public static void addDisassemble(DisassembleData data){
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
            SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
            mapper.addDisassembleEvent(data);
        }
    }

    public static List<DisassembleData> getDisassembleData(String playerName){
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
            SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
            List<DisassembleData> disassembleData = mapper.selectDisassembleEvent(playerName);
            return disassembleData;
        }
    }

    public static List<DisassembleData> getDisassembleData(String playerName, String target){
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()){
            SqlDataMapper mapper = sqlSession.getMapper(SqlDataMapper.class);
            List<DisassembleData> disassembleData = mapper.selectDisassembleEventAndTarget(playerName,target);
            return disassembleData;
        }
    }

    public static void deleteDisassemble(String playerName){

    }
}
