package com.cirle.scientific.questionnaire.valueobject;

import com.cirle.scientific.questionnaire.entity.QuestionnaireEntity;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 获取所有问卷值对象
 */
@Data
@ApiModel("问卷集合查询结果对象")
public class GetQuestionnairesVO {

    @ApiModelProperty("问卷集合")
    private List<Questionnaire> list;

    public void parse(QuestionnaireEntity entity) {
        if (list == null) list = new ArrayList<>();
        Questionnaire questionnaire = new Questionnaire();
        questionnaire.parse(entity);
        list.add(questionnaire);
    }

    public void parseAll(Collection<QuestionnaireEntity> entities) {
        if (entities == null) {
            return;
        }
        entities.forEach(this::parse);
    }

    @Data
    public static class Questionnaire {
        @ApiModelProperty("问卷ID")
        private String id;

        @ApiModelProperty("问卷名")
        private String name;

        @ApiModelProperty("问卷备注")
        @JsonInclude(JsonInclude.Include.NON_NULL)
        private String remark;

        @ApiModelProperty("问卷创建时间")
        private LocalDateTime createTime;

        @ApiModelProperty("问卷最近一次修改时间")
        @JsonInclude(JsonInclude.Include.NON_NULL)
        private LocalDateTime lastModifiedTime;

        private void parse(QuestionnaireEntity entity) {
            setId(entity.getId());
            setName(entity.getName());
            setRemark(entity.getRemark());
            setCreateTime(entity.getCreateTime());
            setLastModifiedTime(entity.getLastModifiedTime());
        }
    }

}
