package com.ruoyi.file.model;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.PathUtils;
import com.ruoyi.file.enums.FileType;
import lombok.Data;

import java.io.File;
import java.util.List;

@Data
public final class FileModel
{
    private String fileName;
    private String filePath;
    private Integer type;
    private List<FileModel> files;

    public FileModel()
    {
    }

    public FileModel(File file)
    {
        fileName = file.getName();
        if(StringUtils.isEmpty(fileName))
            fileName = PathUtils.normalizeSlash(file.getPath());
        else
        {
            if(file.isDirectory())
                fileName += "/";
        }
        try
        {
            filePath = file.getCanonicalPath();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            filePath = file.getAbsolutePath();
        }
        filePath = PathUtils.normalizeSlash(filePath);
        type = FileType.FileType(file);
    }
}
