package com.bocloud.cmp.model.h3c;

import com.bocloud.cmp.model.h3c.utils.ElementUtils;
import com.bocloud.common.utils.ListTool;
import org.w3c.dom.Element;

import java.util.List;

/**
 * 存储池
 */
public class H3cStoragePoolModel {
    /**
     * 主机ID。
     * 长整数（long）类型。
     */
    private Long hostId;
    /**
     * 主机名称 字符串（String）类型
     */
    private String hostName;
    /**
     * 存储池名称 。
     * 字符串（String）类型。
     */
    private String name;
    /**
     * 存储类型，logical：LVM逻辑存储卷，iscsi：ISCSI网络存储，dir：本地文件目录，netfs：NFS网络文件系统，fs：共享文件系统，cifs：Windows系统共享目录
     * 字符串（String）类型。
     */
    private String type;
    /**
     * 存储路径
     * 字符串（String）类型。
     */
    private String path;
    /**
     * 主机IP
     * 字符串（String）类型。
     */
    private String hostIp;
    /**
     * 是否自动启动
     * 布尔类型。
     */
    private Boolean autoStart;
    /**
     * 源存储名称
     * 字符串（String）类型。
     */
    private String srcName;
    /**
     * 源主机IP
     * 字符串（String）类型。
     */
    private String srcHost;
    /**
     * 源存储路径
     * 字符串（String）类型。
     */
    private String srcPath;
    /**
     * 源存储路径
     * 字符串（String）类型。
     */
    private String remoteDir;
    /**
     * 共享存储类型，iscsi：iSCSI共享文件系统，fc：FC共享文件系统
     * 字符串（String）类型。
     */
    private String fsType;
    /**
     * 共享文件系统ID。
     * 长整数（long）类型。
     */
    private Long fsId;
    /**
     * 主机池名称
     * 字符串（String）类型。
     */
    private String hpName;
    /**
     * 共享文件系统名称
     * 字符串（String）类型。
     */
    private String fsName;
    /**
     * 用户名
     * 字符串（String）类型。
     */
    private String userName;
    /**
     * 密码
     * 字符串（String）类型。
     */
    private String pwd;
    /**
     * 文档里面没有 FIXME
     */
    private String targetPath;
    private List<RsFsLunInfo> rsFsLunInfos;
    private long totalSize;
    private long freeSize;
    private int status;

    public String toCreateString() throws Exception {
        Element storagePool = ElementUtils.creatRoot("storagePool");
        ElementUtils.addChild(storagePool, "hostId", hostId);
        ElementUtils.addChild(storagePool, "hostName", hostName);
        ElementUtils.addChild(storagePool, "name", name);
        switch (this.type) {
            case "logical":
                //LVM逻辑存储卷
                ElementUtils.addChild(storagePool, "targetPath", targetPath);
                ElementUtils.addChild(storagePool, "srcPath", srcPath);
                ElementUtils.addChild(storagePool, "srcName", srcName);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                break;
            case "iscsi":
                //ISCSI网络存储
                ElementUtils.addChild(storagePool, "srcHost", srcHost);
                ElementUtils.addChild(storagePool, "path", path);
                ElementUtils.addChild(storagePool, "srcPath", srcPath);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                break;
            case "dir":
                //本地文件目录
                ElementUtils.addChild(storagePool, "path", srcPath);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                break;
            case "netfs":
                //NFS网络文件系统
                ElementUtils.addChild(storagePool, "hostIp", hostIp);
                ElementUtils.addChild(storagePool, "remoteDir", remoteDir);
                ElementUtils.addChild(storagePool, "path", path);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                break;
            case "fs":
                //共享文件系统
                ElementUtils.addChild(storagePool, "fsType", fsType);
                ElementUtils.addChild(storagePool, "fsId", fsId);
                ElementUtils.addChild(storagePool, "hpName", hpName);
                ElementUtils.addChild(storagePool, "fsName", fsName);
                ElementUtils.addChild(storagePool, "path", path);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                if (!ListTool.isEmpty(rsFsLunInfos)) {
                    for (RsFsLunInfo rsFsLunInfo : rsFsLunInfos) {
                        if (rsFsLunInfo != null) {
                            Element lunInfoElement = ElementUtils.addChild(storagePool, "rsFsLunInfo", null);
                            ElementUtils.addChild(lunInfoElement, "targetHost", rsFsLunInfo.getTargetHost());
                            ElementUtils.addChild(lunInfoElement, "naa", rsFsLunInfo.getNaa());
                            ElementUtils.addChild(lunInfoElement, "lun", rsFsLunInfo.getLun());
                            ElementUtils.addChild(lunInfoElement, "capacity", rsFsLunInfo.getCapacity());
                        }
                    }
                }
                break;
            case "cifs":
                //Windows系统共享目录
                ElementUtils.addChild(storagePool, "hostIp", hostIp);
                ElementUtils.addChild(storagePool, "remoteDir", remoteDir);
                ElementUtils.addChild(storagePool, "pwd", pwd);
                ElementUtils.addChild(storagePool, "path", path);
                ElementUtils.addChild(storagePool, "type", type);
                ElementUtils.addChild(storagePool, "userName", userName);
                ElementUtils.addChild(storagePool, "autoStart", autoStart);
                break;
            default:
                break;
        }
        return ElementUtils.toFormatedXML(storagePool);
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public void setFreeSize(long freeSize) {
        this.freeSize = freeSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public long getFreeSize() {
        return freeSize;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getStatus() {
        return status;
    }

    public static class RsFsLunInfo {
        /**
         * 服务器IP地址。
         * 字符串（String）类型。
         */
        private String targetHost;
        /**
         * 网络地址认证（Network Address Authority ）
         * 字符串（String）类型
         */
        private String naa;
        /**
         * 逻辑单元号 。
         * 字符串（String）类型。
         */
        private String lun;
        /**
         * 容量，单位：字节
         * 长整数（long）类型。
         */
        private Long capacity;

        public RsFsLunInfo(String targetHost, String naa, String lun, Long capacity) {
            this.targetHost = targetHost;
            this.naa = naa;
            this.lun = lun;
            this.capacity = capacity;
        }

        public String getTargetHost() {
            return targetHost;
        }

        public void setTargetHost(String targetHost) {
            this.targetHost = targetHost;
        }

        public String getNaa() {
            return naa;
        }

        public void setNaa(String naa) {
            this.naa = naa;
        }

        public String getLun() {
            return lun;
        }

        public void setLun(String lun) {
            this.lun = lun;
        }

        public Long getCapacity() {
            return capacity;
        }

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

    public Long getHostId() {
        return hostId;
    }

    public void setHostId(Long hostId) {
        this.hostId = hostId;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public String getName() {
        return name;
    }

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

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getHostIp() {
        return hostIp;
    }

    public void setHostIp(String hostIp) {
        this.hostIp = hostIp;
    }

    public Boolean getAutoStart() {
        return autoStart;
    }

    public void setAutoStart(Boolean autoStart) {
        this.autoStart = autoStart;
    }

    public String getSrcName() {
        return srcName;
    }

    public void setSrcName(String srcName) {
        this.srcName = srcName;
    }

    public String getSrcHost() {
        return srcHost;
    }

    public void setSrcHost(String srcHost) {
        this.srcHost = srcHost;
    }

    public String getSrcPath() {
        return srcPath;
    }

    public void setSrcPath(String srcPath) {
        this.srcPath = srcPath;
    }

    public String getRemoteDir() {
        return remoteDir;
    }

    public void setRemoteDir(String remoteDir) {
        this.remoteDir = remoteDir;
    }

    public String getFsType() {
        return fsType;
    }

    public void setFsType(String fsType) {
        this.fsType = fsType;
    }

    public Long getFsId() {
        return fsId;
    }

    public void setFsId(Long fsId) {
        this.fsId = fsId;
    }

    public String getHpName() {
        return hpName;
    }

    public void setHpName(String hpName) {
        this.hpName = hpName;
    }

    public String getFsName() {
        return fsName;
    }

    public void setFsName(String fsName) {
        this.fsName = fsName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getTargetPath() {
        return targetPath;
    }

    public void setTargetPath(String targetPath) {
        this.targetPath = targetPath;
    }

    public List<RsFsLunInfo> getRsFsLunInfos() {
        return rsFsLunInfos;
    }

    public void setRsFsLunInfos(List<RsFsLunInfo> rsFsLunInfos) {
        this.rsFsLunInfos = rsFsLunInfos;
    }
}
