package ub.scp2.entities;

/**
 * FileTask.java -this class is an entity binded to the task_file table from the
 * database
 */
public class FileTask {

    /**
     *
     */
    private static final long serialVersionUID = 39263333373223362L;

    private Long fileId;
    private Task task;
    private String filename;
    private boolean shared;
    private byte[] content;

    public FileTask() {
    }

    public FileTask(Task task, String filename) {
        this.task = task;
        this.filename = filename;
    }

    public Long getFileId() {
        return fileId;
    }

    public void setFileId(Long fileId) {
        this.fileId = fileId;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }
    
    public void setFilenameNoExt(String filename) {
        String ext = "";
        if (this.filename != null){
            int pos = this.filename.lastIndexOf(".");
            if (pos >= 0)
                ext = this.filename.substring(pos);
        }
        this.filename = filename + ext;
    }
    
    public String getFilenameNoExt(){
        if (this.filename == null){
            return null;
        }
        int pos = this.filename.lastIndexOf(".");
        if (pos >= 0)
            return this.filename.substring(0, this.filename.lastIndexOf("."));
        else
            return this.filename;
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public boolean isShared() {
        return shared;
    }

    public void setShared(boolean shared) {
        this.shared = shared;
    }
}
