package com.bocloud.cmp.model.installation.catalog;

import com.alibaba.fastjson.annotation.JSONField;

import java.math.BigDecimal;
import java.util.List;

public class Hardware {
    /**
     * core
     * memory
     * cpu:0
     * cpu:1
     * pci
     * pci:0
     * storage
     * disk:0
     * volume:0
     * volume:1
     * volume:2
     * volume:3
     * ...
     */
    @JSONField(name = "id")
    private String pciId;
    /**
     * system
     * bus
     * memory
     * processor
     * bridge
     * storage
     * disk
     * volume
     * network
     * generic
     * communication
     * display
     */
    @JSONField(name = "class")
    private String className;
    /**
     * true
     */
    private Boolean claimed;
    /**
     * Computer,Motherboard,System memory,....
     */
    private String description;
    /**
     * "PCI:0000:03:00.0"
     */
    private String handle;
    /**
     * I350 Gigabit Network Connection
     * <p>
     * MegaRAID SAS-3 3108 [Invader]
     */
    private String product;
    /**
     * Intel Corp.
     * <p>
     * LSI Logic / Symbios Logic
     */
    private String vendor;
    /**
     * 3a,3b...
     */
    @JSONField(name = "physid")
    private String physId;
    /**
     * cpu@0
     * <p>
     * pci@0000:ff:0c.0
     * <p>
     * scsi@10:2.0.0
     */
    @JSONField(name = "businfo")
    private String busInfo;
    /**
     * "logicalname": "eth0",
     * <p>
     * "logicalname": "/dev/sda",
     */
    @JSONField(name = "logicalname")
    private String logicalName;
    /**
     * "serial": "00:9c:02:a1:9b:72",
     * <p>
     * "serial": "500143802251CDC0",
     */
    private String serial;
    /**
     * bytes,Hz,bit/s
     */
    private String units;
    /**
     * 大小
     */
    private BigDecimal size;
    /**
     * 容量，cpu跟网卡有
     */
    private Long capacity;
    /**
     * 32,64
     */
    private Long width;
    /**
     * 时钟频率
     * <p>
     * 33000000
     */
    private Long clock;
    private String capabilities;
    private String configuration;
    private List<Hardware> children;

    public String getPciId() {
        return pciId;
    }

    public void setPciId(String pciId) {
        this.pciId = pciId;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public Boolean getClaimed() {
        return claimed;
    }

    public void setClaimed(Boolean claimed) {
        this.claimed = claimed;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getVendor() {
        return vendor;
    }

    public void setVendor(String vendor) {
        this.vendor = vendor;
    }

    public String getPhysId() {
        return physId;
    }

    public void setPhysId(String physId) {
        this.physId = physId;
    }

    public String getBusInfo() {
        return busInfo;
    }

    public void setBusInfo(String busInfo) {
        try {
            String[] arr = busInfo.split("\\,|\\@|\\:|\\.");
            this.busInfo = String.format("%s@%s:%s:%s.%s",
                arr[0],
                this.addZeroForNum(arr[1], 4),
                this.addZeroForNum(arr[2], 2),
                this.addZeroForNum(arr[3], 2),
                this.addZeroForNum(arr[4], 2));
            return;
        } catch (Exception ignored) {
        }
        this.busInfo = busInfo;
    }

    public String getUnits() {
        return units;
    }

    public void setUnits(String units) {
        this.units = units;
    }

    public BigDecimal getSize() {
        return size;
    }

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

    public Long getCapacity() {
        return capacity;
    }

    public void setCapacity(Long capacity) {
        this.capacity = capacity;
    }

    public String getCapabilities() {
        return capabilities;
    }

    public void setCapabilities(String capabilities) {
        this.capabilities = capabilities;
    }

    public String getConfiguration() {
        return configuration;
    }

    public void setConfiguration(String configuration) {
        this.configuration = configuration;
    }

    public List<Hardware> getChildren() {
        return children;
    }

    public void setChildren(List<Hardware> children) {
        this.children = children;
    }

    public String getHandle() {
        return handle;
    }

    public void setHandle(String handle) {
        this.handle = handle;
    }

    public String getLogicalName() {
        return logicalName;
    }

    public void setLogicalName(String logicalName) {
        this.logicalName = logicalName;
    }

    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    public Long getWidth() {
        return width;
    }

    public void setWidth(Long width) {
        this.width = width;
    }

    public Long getClock() {
        return clock;
    }

    public void setClock(Long clock) {
        this.clock = clock;
    }

    public String getDescription() {
        return description;
    }

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

    private String addZeroForNum(String str, int strLength) {
        int strLen = str.length();
        if (strLen < strLength) {
            while (strLen < strLength) {
                str = "0" + str;// 左补0
                strLen = str.length();
            }
        }
        return str;
    }
}
