package com.qmth.teachcloud.mark.dto;

import java.util.Map;

import javax.validation.constraints.NotNull;

import org.apache.commons.collections4.CollectionUtils;

import com.qmth.boot.core.exception.ParameterException;
import com.qmth.teachcloud.mark.entity.ScanPaperPage;

public class ScanOmrTaskResultPageDto {

	@NotNull(message = "任务pageIndex不能为空")
	private Integer index;

	private Boolean absent;

	private Boolean breach;

	private Map<Integer, String> question;

	private Map<Integer, String> selective;

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public Boolean getAbsent() {
		return absent;
	}

	public void setAbsent(Boolean absent) {
		this.absent = absent;
	}

	public Boolean getBreach() {
		return breach;
	}

	public void setBreach(Boolean breach) {
		this.breach = breach;
	}

	public Map<Integer, String> getQuestion() {
		return question;
	}

	public void setQuestion(Map<Integer, String> question) {
		this.question = question;
	}

	public Map<Integer, String> getSelective() {
		return selective;
	}

	public void setSelective(Map<Integer, String> selective) {
		this.selective = selective;
	}

	public ScanPaperPage update(ScanPaperPage page) {
		if (absent != null) {
			page.getAbsent().setResult(absent);
		}
		if (breach != null) {
			page.getBreach().setResult(breach);
		}
		if (question != null && !question.isEmpty()) {
			if (page.getQuestion() == null || CollectionUtils.isEmpty(page.getQuestion().getResult())) {
				throw new ParameterException("page[" + page.getPageIndex() + "]没有question信息");
			}
			for (Map.Entry<Integer, String> entry : question.entrySet()) {
				page.getQuestion().getResult().set(entry.getKey() - 1, entry.getValue());
			}
		}
		if (selective != null && !selective.isEmpty()) {
			if (page.getSelective() == null || CollectionUtils.isEmpty(page.getSelective().getResult())) {
				throw new ParameterException("page[" + page.getPageIndex() + "]没有selective信息");
			}
			for (Map.Entry<Integer, String> entry : question.entrySet()) {
				page.getSelective().getResult().set(entry.getKey() - 1, entry.getValue());
			}
		}
		return page;
	}
}
