package config

import (
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v2"
)

var Cfg Config

type Config struct {
	Pages []PageItem `yaml:"pages,flow"`
	Bot   Bot
}

type PageItem struct {
	Page       string
	UpdateTime []string `yaml:"update_time,flow"`
	RoomID     string   `yaml:"room_id"`
}

type Bot struct {
	HomeserverUrl string `yaml:"homeserver_url"`
	User          string
	Password      string
}

func LoadConfig() {
	file, err := ioutil.ReadFile("./config.yaml")

	if err != nil {
		log.Fatalln("failed to load yaml file", err)
	}

	err = yaml.Unmarshal(file, &Cfg)

	if err != nil {
		log.Fatalln("failed to unmarshal config", err)
	}
}
