package com.prolog.cs.biz.outbound.utils;

import com.prolog.cs.biz.outbound.core.SpringUtils;
import com.prolog.cs.biz.outbound.dao.StatusRecordMapper;
import com.prolog.cs.biz.outbound.model.entity.StatusRecordDO;
import com.prolog.cs.biz.outbound.model.WAVE_STATUS;
import com.prolog.framework.authority.core.dto.UserDTO;
import com.prolog.framework.bz.core.model.ModelUtils;
import com.prolog.framework.utils.MapUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class StatusUtil {

    private static Logger logger = LoggerFactory.getLogger(BillUtils.class);


    public static boolean updateWaveStartStatus(String waveId, WAVE_STATUS waveStatus, UserDTO userDto) {
        String code = waveStatus.getCode();
        String name = waveStatus.getName();
        StatusRecordDO statusRecordDO = new StatusRecordDO();
        statusRecordDO.setStatusCode(code);
        statusRecordDO.setStatusName(name);
        statusRecordDO.setBizId(waveId);
        statusRecordDO.setBizType("wave");
        Date now = new Date();
        statusRecordDO.setStartTime(now);

        StatusRecordMapper statusRecordMapper = SpringUtils.getBeansByType(StatusRecordMapper.class);
        if (userDto != null) {

            ModelUtils.setBaseInfo(statusRecordDO, ModelUtils.OpType.INSERT, userDto);
        }
        statusRecordMapper.save(statusRecordDO);
        return true;
    }

    public static boolean updateWaveEndStatus(String waveId, WAVE_STATUS waveStatus, UserDTO userDto) {
        String code = waveStatus.getCode();
        StatusRecordMapper statusRecordMapper = SpringUtils.getBeansByType(StatusRecordMapper.class);
        statusRecordMapper.updateEndTime(waveId, new Date(), code);
        return true;
    }

    public static List<StatusRecordDO> findStatus(String bizId) {
        Map<String, Object> bizIdMap = MapUtils.put("bizId", bizId).getMap();
        StatusRecordMapper statusRecordMapper = SpringUtils.getBeansByType(StatusRecordMapper.class);
        return statusRecordMapper.findByMap(bizIdMap, StatusRecordDO.class);
    }


}
