package com.example.demo.dto.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.LinkedList;
import java.util.List;

/**
 * @Author hxh
 * @Date 2020-09-16 0:43
 * @Descrption TODO
 */
@ApiModel(value = "StemDto  题目传输体，包含题号、年级、题目类型等信息，选项，答案，解析",description = "题目")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class StemDto {

    @ApiModelProperty("题号")
    private String id;

    @ApiModelProperty("题干")
    private String name;

    @ApiModelProperty("题目类型(单选，多选)")
    private String type;

    @ApiModelProperty("年级分类")
    private String groupName;

    @ApiModelProperty("年级")
    private String gradeName;

    @ApiModelProperty("学科")
    private String subject;

    @ApiModelProperty("答案")
    private List<String> answer;

    @ApiModelProperty("解析")
    private String analysis;

    @ApiModelProperty("选项集")
    private List<OptionDto> optionList;

    //根据optionList设置答案
    public boolean setAns(){
        answer = new LinkedList<>();
        if(this.optionList.size()>0){
            for(OptionDto option : optionList){
                if(option.getIsRight()){
                    int num = optionList.indexOf(option);
                    answer.add(String.valueOf((char)('A'+num))); //'A' 68
                }
            }
            System.out.println(answer);
            return true;
        }
        return false;
    }
}
