package vut.msa.pojos;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import vut.msa.enums.BackupType;

/**
 * Trieda predstavuje zalohu ulozenu na server. Trieda je namapovana na tabulku
 * backups v databaze.
 */
public class Backup implements Serializable{

    private int id;
    private Client client;
    private String path;
    private String type;
    private Timestamp uploadDate;
    private double size;

    private int success;
    private int version;
    private int documentsCount;

    public Backup() {
        this.id = 0;
        this.client = new Client();
        this.path = "";
        this.type = BackupType.FULL.name();
        this.uploadDate = new Timestamp(new Date().getTime());
        this.size = 0;
        this.success = 0;
    }

    public Backup(int id, Client client, Date uploadDate, double size, 
                    int success, String path, BackupType type) {
        this.id = id;
        this.client = client;
        this.path = path;
        this.uploadDate = new Timestamp(uploadDate.getTime());
        this.size = size;
        this.success = success;
        this.type = type.name();
    }

    //PROPERTY: client
    public Client getClient() { return client; }
    public void setClient(Client client) { this.client = client; }

    //PROPERTY: documentsCount
    public int getDocumentsCount() { return documentsCount; }
    public void setDocumentsCount(int documentsCount) { this.documentsCount = documentsCount; }

    //PROPERTY: id
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    //PROPERTY: path
    public String getPath() { return path; }
    public void setPath(String path) { this.path = path; }

    //PROPERTY: size
    public double getSize() { return size; }
    public void setSize(double size) { this.size = size; }

    //PROPERTY: success
    public int getSuccess() { return success; }
    public void setSuccess(int success) { this.success = success; }

    //PROPERTY: type
    public String getType() { return type; }
    public void setType(String type) { this.type = type; }

    //PROPERTY: uploadDate
    public Timestamp getUploadDate() { return uploadDate; }
    public void setUploadDate(Date uploadDate) {
        this.uploadDate = new Timestamp(uploadDate.getTime());
    }

    //PROPERTY: version
    public int getVersion() { return version; }
    public void setVersion(int version) { this.version = version; }

    public String getUploadDateString() {
        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
        Date uploaded = new Date(uploadDate.getTime());
        return format.format(uploaded);
    }

    public String getUploadTimeString() {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        Date uploaded = new Date(uploadDate.getTime());
        return format.format(uploaded);
    }
}
