package app

import (
	"os"

	"gopkg.in/yaml.v3"
)

type (
	DomainRecords map[string]string
	Domain        map[string]DomainRecords
)

type DigitalOceanService struct {
	Token   string                   `yaml:"token"`
	Domains map[string]DomainRecords `yaml:"domains"`
}

type Providers struct {
	Token   string                   `yaml:"token"`
	Domains map[string]DomainRecords `yaml:"domains"`
}

type Services struct {
	IPLookup string `yaml:"IPLookup"`
	// DigitalOcean DigitalOceanService `yaml:"digitalocean"`
}

type Config struct {
	Services  Services `yaml:"services"`
	Providers map[string]map[string]interface{}
	Updates   map[string]Domain
}

func LoadConfig(filename string) (*Config, error) {
	cfg := Config{
		Services: Services{
			IPLookup: "ipecho",
		},
	}

	data, err := os.ReadFile(filename)
	if err == nil {
		err = yaml.Unmarshal(data, &cfg)
	}
	return &cfg, err
}
