package me.qwq.doghouse.entity;

import com.baomidou.mybatisplus.annotation.IdType;

import java.util.List;
import jakarta.validation.constraints.NotBlank;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import me.qwq.doghouse.enums.MetaTypeEnum;
import me.qwq.doghouse.interfaces.IFriendlyName;
import me.qwq.doghouse.validator.FriendlyNameValid;
/**
 * Cate for category
 * 
 * @author Doghole
 * @since 2021-12-01
 * @see Meta
 */
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("meta")
@FriendlyNameValid
public class Cate extends Meta implements Serializable, ITreeView<Cate>, IFriendlyName {
    
    @TableId(value = "mid", type=IdType.AUTO)
    private Long mid;
    
    @TableField("name")
    @NotBlank(message = "分类名称不允许为空")
    private String name;

    @TableField("type")
    private MetaTypeEnum type = MetaTypeEnum.CATEGORY;
    
    @TableField("parent_id")
    private Long parentId;

    @TableField("friendly_name")
    private String friendlyName;
    
    @TableField("description")
    private String description;
    /**
     * 排序
     */
    @TableField("no")
    private Integer no;
    
    /* 
     * FOR TREEVIEW USE.
     */
    
    @TableField(exist=false)
    private List<Cate> children;
    
    public String getTitle() {
        return getName();
    }
    
    public Long getId() {
        return getMid();
    }
    
    public Boolean getHasChildren() {
        return childrenCount > 0;
    }

    @TableField(exist=false)
    private Boolean checked = false;
    
    @TableField(exist=false)
    private Boolean spread = false;
    
    @TableField(value = "post_count", exist = false)
    private Long postCount = 0L;
    

    @TableField(value = "children_count", exist = false)
    private Long childrenCount = 0L;

}
