package main

import (
	"log"
	"os"

	"github.com/stretchr/testify/assert/yaml"
)

type RaspberryPi struct {
	Name            string   `yaml:"name"`
	AuthorizedUsers []string `yaml:"authorized_users"`
	Hostname        string   `yaml:"hostname"`
	Port            string   `yaml:"port"`
	Username        string   `yaml:"username"`
	Password        string   `yaml:"password,omitempty"` // optional
}

type RaspiConfig struct {
	SuperAdmin string        `yaml:"super_admin"`
	Raspis     []RaspberryPi `yaml:"raspis"`
}

func readConfig() (RaspiConfig, bool) {
	data, err := os.ReadFile("raspis.yaml")
	if err != nil {
		log.Printf("Failed to read config YAML file (raspis.yaml): %v", err)
		return RaspiConfig{}, false
	}

	var cfg RaspiConfig
	if err := yaml.Unmarshal(data, &cfg); err != nil {
		log.Printf("Failed to parse YAML file (raspis.yaml): %v", err)
		return RaspiConfig{}, false
	}

	return cfg, true
}
