package cn.stylefeng.team.portal.modular.management.entity;

import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pidset.callback.PidSettable;
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractSortedTreeNode;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.List;

@TableName("portal_news_category")
@Data
@EqualsAndHashCode(callSuper = true)
public class PortalNewsCategory extends BaseEntity implements PidSettable, AbstractSortedTreeNode<PortalNewsCategory> {

    @TableId(value = "category_id", type = IdType.ASSIGN_ID)
    @ChineseDescription("主键id")
    private Long categoryId;

    @TableField("design_id")
    @ChineseDescription("门户设计id")
    private Long designId;

    @TableField("parent_id")
    @ChineseDescription("父级分类id")
    private Long parentId;

    @TableField("parent_id_list")
    @ChineseDescription("父级分类id集合")
    private String parentIdList;

    @TableField("category_name")
    @ChineseDescription("类别的名称")
    private String categoryName;

    @TableField("fld_sort")
    @ChineseDescription("类别的顺序")
    private BigDecimal fldSort;

    @TableField(value = "version_flag", fill = FieldFill.INSERT)
    @ChineseDescription("乐观锁")
    @Version
    private Long versionFlag;

    @TableField(value = "del_flag", fill = FieldFill.INSERT)
    @ChineseDescription("是否删除：Y-删除，N-未删除")
    @TableLogic
    private String delFlag;

    @TableField(value = "tenant_id", fill = FieldFill.INSERT)
    @ChineseDescription("租户id")
    private Long tenantId;

    @ChineseDescription("子节点")
    @TableField(exist = false)
    private List<PortalNewsCategory> children;

    @Override
    public Long getCurrentId() {
        return this.categoryId;
    }

    @Override
    public void setParentIdListString(String parentIdListString) {
        this.parentIdList = parentIdListString;
    }

    @Override
    public String getParentIdListString() {
        return this.parentIdList;
    }

    @Override
    public String getNodeId() {
        if (this.categoryId == null) {
            return "";
        }
        return this.categoryId.toString();
    }

    @Override
    public String getNodeParentId() {
        if (this.parentId == null) {
            return "";
        }
        return this.parentId.toString();
    }

    @Override
    public void setChildrenNodes(List<PortalNewsCategory> childrenNodes) {
        this.children = childrenNodes;
    }

    @Override
    public BigDecimal getSort() {
        return this.fldSort;
    }
}