package main

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type CompCfg struct {
	Name string `yaml:"Name"`
	URL  string `yaml:"URL"`
}

type SuiteCfg struct {
	Name       string    `yaml:"Name"`
	Components []CompCfg `yaml:"Components"`
}

type ReleaseCfg struct {
	Release      string     `yaml:"Release"`
	RepoURL      string     `yaml:"RepoURL"`
	ReleaseIndex string     `yaml:"ReleaseIndex"`
	Suites       []SuiteCfg `yaml:"Suites"`
}

type PkgwebCfg struct {
	PkgSets []ReleaseCfg `yaml:"PkgSets"`
}

func readConfig(fname string) *PkgwebCfg {

	data, err := ioutil.ReadFile(fname)
	if err != nil {
		log.Fatal("Error while reading file: ", err)
	}

	cfg := new(PkgwebCfg)

	err = yaml.Unmarshal(data, cfg)
	if err != nil {
		log.Fatal("Error while reading configuration: ", err)
	}
	return cfg
}