package com.bocloud.nms.model.hillstone;

import java.text.DecimalFormat;
import java.util.Objects;
import java.util.Optional;

// 系统配置的备份文件
public class ConfigBackupModel extends HillStoneGenericModel {
    private Long vendorId; // 所属平台
    private String name; // 名称
    private String description; // 描述
    private String timestamp; // 保存时间
    private Long size; // 大小，字节
    private String version; // 软件版本
    private String author; // 用户
    private String way; // 备份源
    private String sizeString; // 大小，字符串

    public Long getVendorId() {
        return vendorId;
    }

    public void setVendorId(Long vendorId) {
        this.vendorId = vendorId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getWay() {
        return way;
    }

    public void setWay(String way) {
        this.way = way;
    }

    public String getSizeString() {
        return Optional.ofNullable(this.getSize()).map(o -> new DecimalFormat("0.00").format(Double.parseDouble(String.valueOf(o)) / (2 << 19))).orElse(null);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ConfigBackupModel that = (ConfigBackupModel) o;
        return Objects.equals(vendorId, that.vendorId) &&
            Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(vendorId, name);
    }
}
