package com.xiaoniu.system.platformsettings.region.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 省市区树结构实体类
 *
 * @author Wzp
 */
@Data
@Schema(description = "省市区树结构实体类")
public class RegionTreeVO implements Serializable {

    /**
     * 节点ID
     */
    private Integer value;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<RegionTreeVO> children;

    public RegionTreeVO() {

    }

    public RegionTreeVO(RegionVO regionVO) {
        this.value = regionVO.getId();
        this.label = regionVO.getName();
        this.children = regionVO.getChildren().stream().map(RegionTreeVO::new).collect(Collectors.toList());
    }
}