package me.qwq.doghouse.entity;

import com.baomidou.mybatisplus.annotation.IdType;

import org.springframework.web.util.UriUtils;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import me.qwq.doghouse.enums.MetaTypeEnum;

/**
 * Meta, super class of Cate and Tag
 *
 * @author Doghole
 * @since 2021-12-01
 * @see Cate
 * @see Tag
 */
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Meta extends Model<Meta> implements Serializable {
    
    /**
     * 标签名称
     */
    @TableId(value = "mid", type=IdType.AUTO)
    private Long mid;
    
    @TableField("name")
    private String name;
    
    @TableField("type")
    private MetaTypeEnum type;
    
    @TableField("parent_id")
    private Long parentId;
    
    @TableField("friendly_name")
    private String friendlyName;
    
    public String getUrlEncodedFriendlyName() {
        return UriUtils.encode(getFriendlyName(), StandardCharsets.UTF_8);
    }
    
    @TableField("description")
    private String description;

    @TableField(value = "post_count", exist = false)
    private Long postCount = 0L;
    /**
     * 排序
     */
    @TableField("no")
    private Integer no;
    
    @TableField(exist=false)
    private LocalDateTime updateTime;
}
