package main

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/adamveld12/gopherhole/internal"
)

type StartupConfig struct {
	DatabaseURL string          `json:"database"`
	CacheURL    string          `json:"cache"`
	HTTPAddr    string          `json:"http-addr"`
	DNSAddr     string          `json:"dns-addr"`
	Recursors   []string        `json:"recursors"`
	Rules       []internal.Rule `json:"rules"`
}

func LoadStartupConfig(conf *StartupConfig, file string) error {
	data, err := os.Open(file)
	if err != nil {
		return fmt.Errorf("could not open file: %w", err)
	}

	if err := json.NewDecoder(data).Decode(conf); err != nil {
		return fmt.Errorf("could not read json file: %w", err)
	}

	return nil
}
