package com.fzm.mall.server.admin.goods_center.model;

import com.baomidou.mybatisplus.annotation.*;
import com.fzm.mall.server.admin.util.UUIDUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 商品类别
 * </p>
 *
 * @author fzm
 * @since 2021-03-04
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("goods_category")
@ApiModel(value = "Category对象", description = "商品类别")
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 根类别
     */
    public static final Integer ROOT_LEVEL = 0;

    /**
     * 根类别编号
     */
    public static final String ROOT_CATEGORY_ID = "root";

    /**
     * 类别删除的标识
     */
    public static final Integer CATEGORY_STATUS_DELETED = 0;

    /**
     * 类别有效的标识
     */
    public static final Integer CATEGORY_STATUS_EFFECTIVE = 1;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "系列编号")
    private String categoryId;

    @ApiModelProperty(value = "所属上一级系列编号")
    private String clazzId;

    @ApiModelProperty(value = "层级")
    private Integer level;

    @ApiModelProperty(value = "系列名称")
    private String name;

    @ApiModelProperty(value = "缩略图")
    private String thumb;

    @ApiModelProperty(value = "状态 0: 删除   1: 有效")
    private Integer status;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Long createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateTime;

    @TableField(exist = false)
    @ApiModelProperty(value = "子类别集合")
    private List<Category> childList;

    public void init() {
        /**
         * 创建时记录上级所属上一级系列编号
         */
        setClazzId(getCategoryId());
        /**
         * 新增时，默认设置为有效
         */
        setCategoryId(UUIDUtil.getUUID());
        setStatus(CATEGORY_STATUS_EFFECTIVE);
        setLevel(getLevel() + 1);
    }
}
