package com.microservices.cms.doc.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.microservices.cms.utils.CmsConstants;
import com.microservices.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @author otto
 */
@Data
@ApiModel("栏目对象")
public class CmsDir implements Comparable<CmsDir> {
    /**
     * ID
     */
    @ApiModelProperty(value = "栏目Id", hidden = true)
    private Long id;
    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date createdAt;

    /**
     * 栏目名称
     */
    @Excel(name = "栏目名称")
    @ApiModelProperty("栏目名称")
    private String name;

    /**
     * 排序
     */
    @Excel(name = "排序")
    @ApiModelProperty(value = "排序", hidden = true)
    private Integer sort;

    public String getName() {
        if (name != null) {
            name = name.replaceAll(CmsConstants.DIR_SEPARATOR,
                    CmsConstants.DIR_SEPARATOR_REPLACE);
        }
        return name;
    }

    @Override
    public int compareTo(CmsDir cmsDir) {
        return this.sort - cmsDir.sort;
    }
}
