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

import cn.com.qmth.stmms.ms.admin.dto.MarkUserDTO;
import cn.com.qmth.stmms.ms.core.domain.user.MarkUser;
import cn.com.qmth.stmms.ms.core.domain.user.Role;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.StringJoiner;

/**
 * Created by zhengmin on 2016/11/18.
 */
@Component
public class MarkUserAssembler {

    public MarkUserDTO toDTO(MarkUser markUser){
        MarkUserDTO markUserDTO = null;
        if(markUser != null){
            markUserDTO = new MarkUserDTO();
            markUserDTO.setLoginName(markUser.getLoginName());
            markUserDTO.setName(markUser.getName());
            markUserDTO.setPassword(markUser.getPassword());
            markUserDTO.setSubjectName(markUser.getSubject().getName());
            markUserDTO.setRoleName(markUser.getRole().getName());
            if(Objects.equals(Role.MARK_LEADER.name(), markUser.getRole().name())){
                StringJoiner sj = new StringJoiner(";");
                if(markUser.getOneClickLevel()){
                    sj.add("一键定档");
                }
                if(markUser.getStandardVolume()){
                    sj.add("设立标准卷");
                }
                if(markUser.getLevelCallback()){
                    sj.add("建议档位打回");
                }
                markUserDTO.setMarkRightName(sj.toString());
            } else {
                String markRight = markUser.getMarkRight() == null?"":markUser.getMarkRight().getName();
                markUserDTO.setMarkRightName(markRight);
            }
        }
        return markUserDTO;
    }
}
