package config

import (
	"os"

	"pulsegate/internal/models"
	"gopkg.in/yaml.v3"
)

func LoadConfig(path string) (models.AppConfig, error) {
	var cfg models.AppConfig

	data, err := os.ReadFile(path)
	if err != nil {
		return cfg, err
	}

	err = yaml.Unmarshal(data, &cfg)
	return cfg, err
}

func SaveConfig(path string, cfg models.AppConfig) error {
	data, err := yaml.Marshal(&cfg)
	if err != nil {
		return err
	}

	return os.WriteFile(path, data, 0600)
}