package cn.reghao.tnb.file.app.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.common.auth.UserContext;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author reghao
 * @date 2025-12-05 09:28:00
 */
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public class LocalFile extends BaseObject<Integer> {
    @NotBlank
    private String objectName;
    @NotBlank
    private String objectId;
    @NotBlank
    private String absolutePath;
    @NotBlank
    private String sha256sum;
    @NotBlank
    private String filename;
    @NotBlank
    private String contentType;
    private Integer fileType;
    @NotNull
    private Long size;
    private Long owner;

    public LocalFile(String objectName, String objectId, LocalFile localFile, String filename) {
        this.objectName = objectName;
        this.objectId = objectId;
        this.absolutePath = localFile.getAbsolutePath();
        this.sha256sum = localFile.getSha256sum();
        this.filename = filename;
        this.contentType = localFile.getContentType();
        this.fileType = localFile.getFileType();
        this.size = localFile.getSize();
        this.owner = UserContext.getUserId();
    }

    public LocalFile(String objectName, String objectId, String absolutePath, String sha256sum,
                    String filename, String contentType, int fileType, long size) {
        this.objectName = objectName;
        this.objectId = objectId;
        this.absolutePath = absolutePath;
        this.sha256sum = sha256sum;
        this.filename = filename;
        this.contentType = contentType;
        this.fileType = fileType;
        this.size = size;
        this.owner = UserContext.getUserId();
    }
}
