package com.mini.capi.api.service;

import com.mini.capi.config.component.AppNetworkInfo;
import com.mini.capi.config.component.AppPathInfo;
import com.mini.capi.config.component.AppProcessInfo;
import com.mini.capi.config.component.AppRuntimeInfo;
import com.mini.capi.model.info.*;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class sysService {


    @Resource
    private AppRuntimeInfo appRuntimeInfo;
    @Resource
    private AppPathInfo appPathInfo;
    @Resource
    private AppProcessInfo appProcessInfo;
    @Resource
    private AppNetworkInfo appNetworkInfo;


    public RunInfo getRunInfo() throws Exception {
        return RunInfo.builder()
                .runtimeInfo(RuntimeInfo.builder()
                        .appName(appRuntimeInfo.getAppName())
                        .serverPort(appRuntimeInfo.getServerPort())
                        .activeProfiles(appRuntimeInfo.getActiveProfiles())
                        .springBootVersion(appRuntimeInfo.getSpringBootVersion())
                        .jdkVersion(appRuntimeInfo.getJdkVersion())
                        .build())
                .pathInfo(PathInfo.builder()
                        .workDir(appPathInfo.getWorkDir())
                        .jarDir(appPathInfo.getJarDir())
                        .resourceDir(appPathInfo.getResourceDir())
                        .build())
                .processInfo(ProcessInfo.builder()
                        .pid(appProcessInfo.getPid())
                        .uptime(appProcessInfo.getUptime())
                        .usedHeapMemory(appProcessInfo.getUsedHeapMemory())
                        .maxHeapMemory(appProcessInfo.getMaxHeapMemory())
                        .jvmArgs(appProcessInfo.getJvmArgs())
                        .build())
                .networkInfo(NetworkInfo.builder()
                        .hostName(appNetworkInfo.getHostName())
                        .localIp(appNetworkInfo.getLocalIp())
                        .allIps(appNetworkInfo.getAllIps())
                        .build())
                .build();
    }
}
