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

import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PropertyDto;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

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

@Component
public class PropertyAssembler {

    /**
     * 得到父节点对象
     */
    public Property toProperty(PropertyDto dto) {
        if (dto != null) {
            Property property = new Property();
            property.setCoursePropertyId(dto.getCoursePropertyId());
            property.setParentId(dto.getCoursePropertyId());
            property.setId(dto.getId());
            property.setName(dto.getName());
            property.setRemark(dto.getRemark());
            return property;
        }

        return null;
    }

    /**
     * 得到子类节点对象
     */
    public List<Property> toPropertySon(PropertyDto dto) {
        List<PropertyDto> propertyList = dto.getPropertyList();

        if (CollectionUtils.isEmpty(propertyList)) {
            return null;
        }

        List<Property> properties = new ArrayList<>();
        for (PropertyDto propertyDto : propertyList) {
            Property property = toProperty(propertyDto);
            properties.add(property);
        }

        return properties;
    }

}