package config

import (
	"os"

	"git.atri.dad/atridad/muse/schema"
	"gopkg.in/yaml.v3"
)

// Loads a song definition from a YAML file
func LoadSong(filename string) (*schema.Song, error) {
	data, err := os.ReadFile(filename)
	if err != nil {
		return nil, err
	}

	var song schema.Song
	if err := yaml.Unmarshal(data, &song); err != nil {
		return nil, err
	}

	return &song, nil
}

// Saves a song definition to a YAML file
func SaveSong(filename string, song *schema.Song) error {
	data, err := yaml.Marshal(song)
	if err != nil {
		return err
	}

	return os.WriteFile(filename, data, os.ModePerm)
}
