package config

import (
	"os"

	"gopkg.in/yaml.v3"
)

func LoadSunHPC() (*SunHPCConfig, error) {
	return loadYAML[SunHPCConfig](SunHPCFile)
}

func LoadNodes() (*NodesConfig, error) {
	return loadYAML[NodesConfig](NodesFile)
}

func LoadNetwork() (*NetworkConfig, error) {
	return loadYAML[NetworkConfig](NetworkFile)
}

func LoadDisks() (*DisksConfig, error) {
	return loadYAML[DisksConfig](DisksFile)
}

func LoadServices() (*ServicesConfig, error) {
	return loadYAML[ServicesConfig](ServicesFile)
}

func LoadFirewall() (*FirewallConfig, error) {
	return loadYAML[FirewallConfig](FirewallFile)
}

func loadYAML[T any](path string) (*T, error) {
	data, err := os.ReadFile(path)
	if err != nil {
		return nil, err
	}
	var cfg T
	if err := yaml.Unmarshal(data, &cfg); err != nil {
		return nil, err
	}
	return &cfg, nil
}
