package main

import (
	"log"

	"github.com/spf13/viper"
)

// Outlet definition
type Outlet interface {
	On() error
	Off() error
	Toggle() (bool, error)
	Name() (string, error)
	Status() (bool, error)
	Location() string
	Board() Board
	Channel() uint
}

type config struct {
	outlets []g
}
type g struct {
	n string
	k string
}

func inita() {
	viper.SetConfigName("openpdu")
	viper.SetConfigType("json")
	viper.AddConfigPath(".")
	viper.ReadInConfig()

	viper.Set("sboards[0].name", "ciao")
	viper.Set("sboards[0].type", "virtual")
	viper.Set("sboards[1].name", "ciao1")
	viper.Set("sboards[1].type", "virtual1")
	viper.WriteConfigAs("openpdu_out.json")

	allSettings := viper.AllSettings()
	log.Printf("All settings: %v \n", allSettings)
}

func inzxcit() {
	var err error
	var C = config{
		outlets: []g{
			{n: "pio1", k: "pao1"},
			{n: "pio2", k: "pao2"},
			{n: "pio3", k: "pao3"},
		},
	}

	// err = viper.Marshal(&C)
	// if err != nil {
	// 	log.Printf("unable to decode into struct, %v", err)
	// }

	err = viper.Unmarshal(&C)
	if err != nil {
		log.Printf("unable to decode into struct, %v", err)
	}
}
