package cn.reghao.oss.store.model.po;

import cn.reghao.oss.store.util.UserContext;
import cn.reghao.jutil.jdk.db.BaseObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 文件元数据
 *
 * @author reghao
 * @date 2022-11-21 10:53:10
 */
@NoArgsConstructor
@Setter
@Getter
public class FileMeta extends BaseObject<Integer> {
    private String objectName;
    private String objectId;
    private String pid;
    private String contentId;
    private String sha256sum;
    private String filename;
    private Long size;
    private Integer fileType;
    private String contentType;
    private Integer scope;
    private Integer uploadBy;

    // 目录对象
    public FileMeta(String objectName, String objectId, String filename, String pid, int scope) {
        this.objectName = objectName;
        this.objectId = objectId;
        this.contentId = "0";
        this.filename = filename;
        this.size = 0L;
        this.fileType = 1000;
        this.contentType = "0";
        this.sha256sum = "0";
        this.pid = pid;
        this.uploadBy = UserContext.getUser();
        this.scope = scope;
    }

    public FileMeta(String objectName, String objectId, String contentId, String filename, long size,
                    int fileType, String contentType, String sha256sum, String pid, int scope) {
        this.objectName = objectName;
        this.objectId = objectId;
        this.contentId = contentId;
        this.filename = filename;
        this.size = size;
        this.fileType = fileType;
        this.contentType = contentType;
        this.sha256sum = sha256sum;
        this.pid = pid;
        this.uploadBy = UserContext.getUser();
        this.scope = scope;
    }

    public FileMeta(String objectName, String objectId, String filename, FileMeta fileMeta, int scope) {
        this.objectName = objectName;
        this.objectId = objectId;
        this.contentId = fileMeta.getContentId();
        this.filename = filename;
        this.size = fileMeta.getSize();
        this.fileType = fileMeta.getFileType();
        this.contentType = fileMeta.getContentType();
        this.sha256sum = fileMeta.getSha256sum();
        this.pid = fileMeta.getPid();
        this.uploadBy = UserContext.getUser();
        this.scope = scope;
    }
}
