package cn.reghao.bnt.web.config.spring;

import cn.reghao.bnt.common.machine.*;
import cn.reghao.jutil.jdk.converter.ByteConverter;
import cn.reghao.jutil.jdk.http.WebClient;
import cn.reghao.jutil.jdk.http.WebRequest;
import cn.reghao.jutil.jdk.shell.ShellExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import oshi.SystemInfo;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.software.os.OperatingSystem;

/**
 * @author reghao
 * @date 2023-08-02 09:14:17
 */
@Configuration
public class BeanConfig {
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public WebRequest webRequest() {
        //return new DefaultWebRequest();
        return new WebClient();
    }

    @Bean
    public ShellExecutor shellExecutor() {
        return new ShellExecutor();
    }

    @Bean
    public ByteConverter byteConverter() {
        return new ByteConverter();
    }

    @Bean
    public SystemInfo systemInfo() {
        SystemInfo si = new SystemInfo();
        HardwareAbstractionLayer hal = si.getHardware();
        OperatingSystem operatingSystem = si.getOperatingSystem();
        return si;
    }

    @Bean
    public CPU cpu() {
        return new CPU(systemInfo());
    }

    @Bean
    public Memory memory() {
        return new Memory(systemInfo(), byteConverter());
    }

    @Bean
    public Disk disk() {
        return new Disk(systemInfo(), byteConverter());
    }

    @Bean
    public Network network() {
        return new Network(systemInfo(), byteConverter());
    }

    @Bean
    public OS os() {
        return new OS(systemInfo(), byteConverter());
    }
}
