package com.yuchen.saas.manage.dict.api.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yuchen.saas.manage.dict.api.entity.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.nest.springwrap.core.tool.node.INode;
import org.nest.springwrap.core.tool.utils.Func;

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

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "DictVO对象", description = "DictVO对象")
public class DictVO extends Dict implements INode<DictVO> {
    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;


    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;


    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<DictVO> children;

    @Override
    public List<DictVO> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }

    @Override
    public Boolean getHasChildren() {
        //web端的控件必须返回false才会显示树的下级节点????
        if (Func.isNotEmpty(children)) {
            return true;
        } else {
            return false;
        }
    }


    private String parentName;

    //下面三个字段是前端要求给定的
    @ApiModelProperty(value = "字典名称")
    private String label;

    @ApiModelProperty(value = "字典名称")
    private String text;

    @ApiModelProperty(value = "字典值")
    private String value;

    public String getLabel(){
        return getDictValue();
    }

    public String getText(){
        return getDictValue();
    }

    public String getValue(){
        return getDictKey();
    }

}
