package cn.com.qmth.stmms.biz.common.domain.card;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 卡格式文件内容结构
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerCardSubjectFile {

    private String code;

    private List<AnswerCardSubjectItem> courses = Collections.emptyList();

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public List<AnswerCardSubjectItem> getCourses() {
        return courses;
    }

    public void setCourses(List<AnswerCardSubjectItem> courses) {
        this.courses = courses;
    }

    /**
     * 从输入流解析卡格式文件
     *
     * @param ins
     * @return
     * @throws IOException
     */
    public static List<AnswerCardSubjectFile> parse(InputStream ins) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        List<AnswerCardSubjectFile> list = mapper.readValue(ins, new TypeReference<List<AnswerCardSubjectFile>>() {
        });
        return list;
    }
}
