package cn.com.qmth.stmms.ms.marking.assembler;

import cn.com.qmth.stmms.ms.marking.dto.MarkerDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.com.qmth.stmms.ms.core.domain.MarkSubject;
import cn.com.qmth.stmms.ms.core.domain.user.MarkUser;
import cn.com.qmth.stmms.ms.core.repository.MarkSubjectRepo;

/**
 * Created by zhengmin on 2016/10/20.
 */
@Component
public class MarkerAssembler {

    @Autowired
    private MarkSubjectRepo markSubjectRepo;

    public MarkerDTO toDTO(MarkUser marker){
        MarkerDTO markerDTO = null;
        if(marker != null){
            markerDTO = new MarkerDTO();
            markerDTO.setId(marker.getId());
            markerDTO.setName(marker.getName());
            markerDTO.setMarkRight(marker.getMarkRight());
            markerDTO.setSubject(marker.getSubject());
            markerDTO.setWorkId(marker.getWorkId());
            String markSubjectId = marker.getWorkId() + "-" +marker.getSubject().toString();
            MarkSubject markSubject = markSubjectRepo.findOne(markSubjectId);
            markerDTO.setMarkSubjectId(markSubjectId);
            markerDTO.setMarkStage(markSubject.getStage());
            markerDTO.setGroupId(String.valueOf(marker.getGroupId()));
        }
        return markerDTO;
    }

    public MarkerDTO toScanDTO(MarkUser marker){
        MarkerDTO markerDTO = null;
        if(marker != null){
            markerDTO = new MarkerDTO();
            markerDTO.setId(marker.getId());
            markerDTO.setLoginName(marker.getLoginName());
            markerDTO.setName(marker.getName());
            markerDTO.setWorkId(marker.getWorkId());
            markerDTO.setPassword(marker.getPassword());
            markerDTO.setEnabled(marker.isEnabled());
            markerDTO.setRole(marker.getRole());
        }
        return markerDTO;
    }
}
