package cn.com.qmth.examcloud.core.questions.service.bean;

import cn.com.qmth.examcloud.core.questions.base.question.PaperDetailUnitDto;
import cn.com.qmth.examcloud.core.questions.base.question.QuesOptionDto;
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by songyue on 18/1/5.
 */
@Component
public class PaperDetailUnitDtoAssembler {

    public PaperDetailUnitDto toDto(PaperDetailUnit paperDetailUnit) {
        PaperDetailUnitDto paperDetailUnitDto = new PaperDetailUnitDto();
        paperDetailUnitDto.setId(paperDetailUnit.getId());
        paperDetailUnitDto.setNumber(paperDetailUnit.getNumber());
        paperDetailUnitDto.setScore(paperDetailUnit.getScore());
        paperDetailUnitDto.setOptionOrder(paperDetailUnit.getOptionOrder());
        paperDetailUnitDto.setQuestionType(paperDetailUnit.getQuestionType());
        paperDetailUnitDto.setSubScoreList(paperDetailUnit.getSubScoreList());
        paperDetailUnitDto.setQuesBody(paperDetailUnit.getQuestion().getQuesBody());
        if (paperDetailUnit.getQuestion().getQuesOptions() != null && paperDetailUnit.getQuestion().getQuesOptions().size() > 0) {
            List<QuesOptionDto> quesOptionDtos = new ArrayList<>();
            for (QuesOption quesOption : paperDetailUnit.getQuestion().getQuesOptions()) {
                QuesOptionDto quesOptionDto = new QuesOptionDto();
                quesOptionDto.setNumber(quesOption.getNumber());
                quesOptionDto.setOptionBody(quesOption.getOptionBody());
                quesOptionDtos.add(quesOptionDto);
            }
            paperDetailUnitDto.setQuesOptions(quesOptionDtos);
        }
        return paperDetailUnitDto;
    }

    public List<PaperDetailUnitDto> toDtoList(List<PaperDetailUnit> paperDetailUnitList) {
        List<PaperDetailUnitDto> paperDetailUnitDtos = new ArrayList<>();
        for (PaperDetailUnit pdu : paperDetailUnitList) {
            paperDetailUnitDtos.add(toDto(pdu));
        }
        return paperDetailUnitDtos;
    }
}
