package com.its.pis.process;

import com.its.pis.dao.mapper.UnitSystMapper;
import com.its.pis.dao.mapper.VdsCtlrMapper;
import com.its.pis.dao.mapper.VdsDtctMapper;
import com.its.pis.dao.mapper.VdsStatMapper;
import com.its.pis.dao.mapper.batch.VdsCtlrDao;
import com.its.pis.dao.mapper.batch.VdsDtctDao;
import com.its.pis.entity.TbVdsCtlrStts;
import com.its.pis.entity.voVdsDtctClct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Service
public class DbmsJobProcess extends AbstractDbmsJobProcess {

    private final VdsCtlrDao vdsCtlrDao;
    private final VdsDtctDao vdsDtctDao;

    private final UnitSystMapper unitSystMapper;
    private final VdsCtlrMapper vdsCtlrMapper;
    private final VdsDtctMapper vdsDtctMapper;
    private final VdsStatMapper vdsStatMapper;

    @Override
    protected void postConstruct() {
//        this.unitSystMapper = (UnitSystMapper) AppUtils.getBean(UnitSystMapper.class);
//        this.vdsCtlrMapper = (VdsCtlrMapper) AppUtils.getBean(VdsCtlrMapper.class);
//        this.vdsDtctMapper = (VdsDtctMapper) AppUtils.getBean(VdsDtctMapper.class);
//        this.vdsStatMapper = (VdsStatMapper) AppUtils.getBean(VdsStatMapper.class);
    }

    @Override
    public void process(DbmsJobData data) {
        try {
            int type = data.getType();
            switch(type) {
                case DbmsJobType.DATA_TYPE_CTLR_STTS:
                    List<TbVdsCtlrStts> ctlrSttsList = (List<TbVdsCtlrStts>)data.getData();
                    this.vdsCtlrDao.updateStts(ctlrSttsList, data.isHistory());
                    if (data.isHistory()) {
                        this.vdsCtlrDao.insertStts(ctlrSttsList);
                    }
//                    for (TbVdsCtlrStts vo : ctlrSttsList) {
//                        this.vdsCtlrMapper.updateVdsCtlrStts(vo);   // 상태정보 업데이트
//                        if (data.isHistory()) {
//                            this.vdsCtlrMapper.insertVdsCtlrSttsHs(vo); // 상태정보 이력저장
//                        }
//                    }
                    ctlrSttsList.clear();
                    break;
                case DbmsJobType.DATA_TYPE_DTCT_CLCT:
                    List<voVdsDtctClct> dtctClctList = (List<voVdsDtctClct>)data.getData();
                    //this.vdsDtctDao.updateClct(dtctClctList, data.isHistory());
                    this.vdsDtctDao.insertClct(dtctClctList);
//                    for (voVdsDtctClct vo : dtctClctList) {
//                        this.vdsDtctMapper.updateVdsDtctClctPnst(vo);   // 수집정보 업데이트
//                        this.vdsDtctMapper.insertVdsDtctClct(vo);       // 수집정보 이력저장
//                    }
                    dtctClctList.clear();
                    break;
            }
        } catch (Exception e) {
            log.error("DbmsJobProcess.process: Exception: {}", e.toString());
        }
    }

}
