package me.qwq.doghouse.entity;


import java.io.Serializable;
import java.time.LocalDateTime;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;

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

/**
 * 资产实体类
 * @author Doghole
 *
 */
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain=true)
public class Asset extends Model<Post> implements Serializable {
    
    /**
     * 资产 ID
     */
    @TableId(value="asset_id", type=IdType.AUTO)
    private Long assetId;

    /**
     * 资产路径
     */
    @TableField("path")
    private String path;
    
    /**
     * 资产标题(名称)
     */
    @TableField("title")
    private String title;
    
    /**
     * 获取扩展名
     * @return
     */
    public String getExt() {
        if (StringUtils.isEmpty(path)) {
            return "";
        }
        int lastIndexOfDot = path.lastIndexOf('.');
        if (lastIndexOfDot == -1 || lastIndexOfDot == path.length() - 1) {
            return "";
        }
        return path.substring(lastIndexOfDot + 1).toLowerCase();
    }

    @TableField("file_type")
    private FileTypeEnum fileType;
    
    @TableField("file_size")
    private Long fileSize;

    @TableField("image_width")
    private Integer imageWidth;

    @TableField("image_height")
    private Integer imageHeight;
    
    /**
     * 资产描述
     */
    @TableField("description")
    private String description;

    /**
     * 添加时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("update_time")
    private LocalDateTime updateTime;
    
    @TableField("from_post_id")
    private Long fromPostId;
    
    @TableField(exist=false)
    private String fromPostTitle;

}
