package com.ningdatech.carapi.sys.entity.vo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ningdatech.carapi.common.base.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;

/**
 * 包括id、create_time、created_by、updated_by、update_time、label、parent_id、sort_value 字段的表继承的树形实体
 *
 * @author PoffyZhang
 * @since 2022/09/30
 */
@Getter
@Setter
@Accessors(chain = true)
@ToString(callSuper = true)
public class TreeVO<E, T extends Serializable> extends BaseEntity {

    protected Long id;

    /**
     * 名称
     */
    @ApiModelProperty(value = "名称")
    protected String name;

    /**
     * 菜单标题
     */
    @ApiModelProperty(value = "菜单标题")
    protected String title;

    /**
     * 父菜单ID
     */
    @ApiModelProperty(value = "父ID")
    protected Long pid;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序号")
    protected Integer sort;

    /**
     * 顶层菜单
     */
    @ApiModelProperty(value = "顶层菜单")
    protected String topMenu;

    /**
     * 路径
     */
    @ApiModelProperty(value = "路径")
    protected String path;


    @ApiModelProperty(value = "子节点", hidden = true)
    protected List<E> children;

    /**
     * 层级
     */
    @ApiModelProperty(value = "层级")
    protected Integer level = 1;


    /**
     * 初始化子类
     */
    @JsonIgnore
    public void initChildren() {
        if (getChildren() == null) {
            this.setChildren(new ArrayList<>());
        }
    }

    @JsonIgnore
    public void addChildren(E child) {
        initChildren();
        children.add(child);
    }

    @Override
    public Object clone() throws CloneNotSupportedException{
        return super.clone();
    }
}
