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

import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.oss.api.constant.ObjectType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author reghao
 * @date 2023-11-11 00:06:21
 */
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public class DiskFile extends BaseObject<Integer> {
    private Integer channelCode;
    private String fileId;
    private String pid;
    private String path;
    private String filename;
    private Integer fileType;
    private String sha256sum;
    private Long size;
    private Long owner;
    private transient List<DiskFile> children = new ArrayList<>();

    // 网盘根节点, 系统中有且仅有一个, 由所有 owner 共享
    public DiskFile(long owner) {
        this.channelCode = 0;
        this.fileId = "0";
        this.pid = "00";
        this.path = "/";
        this.filename = "/";
        this.fileType = ObjectType.Dir.getCode();
        this.sha256sum = "0";
        this.size = 0L;
        this.owner = UserContext.getUserId();
    }

    public DiskFile(String fileId, String pid, String path, String filename) {
        this.channelCode = 0;
        this.fileId = fileId;
        this.pid = pid;
        this.path = path;
        this.filename = filename;
        this.fileType = ObjectType.Dir.getCode();
        this.sha256sum = "0";
        this.size = 0L;
        this.owner = UserContext.getUserId();
    }

    public DiskFile(int channelCode, String fileId, String pid, String path, String filename,
                    int fileType, String sha256sum, long size) {
        this.channelCode = channelCode;
        this.fileId = fileId;
        this.pid = pid;
        this.path = path;
        this.filename = filename;
        this.fileType = fileType;
        this.sha256sum = sha256sum;
        this.size = size;
        this.owner = UserContext.getUserId();
    }
}
