package cn.reghao.autodop.common.machine;

import cn.reghao.jdkutil.machine.Disk;
import cn.reghao.jdkutil.machine.MachineId;
import cn.reghao.jdkutil.machine.Network;
import cn.reghao.jdkutil.machine.OsDetail;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author reghao
 * @date 2020-10-22 15:47:58
 */
public class Machine {
    private final Os os;
    private final Cpu cpu;
    private final Memory memory;

    public Machine(Os os, Cpu cpu, Memory memory) {
        this.os = os;
        this.cpu = cpu;
        this.memory = memory;
    }

    public MachineDetail detail() {
        MachineDetail machineDetail = new MachineDetail();
        machineDetail.setMachineId(MachineId.id());
        machineDetail.setOsDetail(os.detail());
        machineDetail.setNetworkDetails(Network.details());
        machineDetail.setCpuDetail(cpu.detail());
        machineDetail.setMemoryDetail(memory.detail());
        machineDetail.setDiskDetails(Disk.details());
        return machineDetail;
    }

    public MachineStat stat() {
        MachineStat machineStat = new MachineStat();
        machineStat.setMachineId(MachineId.id());
        machineStat.setMemoryDetail(memory.detail());
        machineStat.setDiskDetails(Disk.details());
        return machineStat;
    }

    @Data
    public static class MachineDetail implements Serializable {
        private static final long serialVersionUID = 1L;

        private String machineId;
        private OsDetail osDetail;
        private List<Network.NetworkDetail> networkDetails;
        private Cpu.CpuDetail cpuDetail;
        private Memory.MemoryDetail memoryDetail;
        private List<Disk.DiskDetail> diskDetails;
    }

    @Data
    public static class MachineStat implements Serializable {
        private static final long serialVersionUID = 1L;

        private String machineId;
        private Memory.MemoryDetail memoryDetail;
        private List<Disk.DiskDetail> diskDetails;
    }
}
