package resolver

import (
	"net/http"

	"dnsupdater/ip/resolver/basic_http"
	"dnsupdater/ip/resolver/jsonip"
)

var services []Service

func Provide(service Service) {
	services = append(services, service)
}

func Get(name string) Service {
	for _, service := range services {
		if service.Name() == name {
			return service
		}
	}
	return nil
}

func init() {
	Provide(jsonip.New())

	Provide(&basic_http.Service{
		ServiceName: "ifconfig.me",
		Url:         "https://ifconfig.me/ip",
	})

	Provide(&basic_http.Service{
		ServiceName: "ip.me",
		Url:         "https://ip.me",
		Headers: http.Header{
			"User-Agent": []string{"curl"},
		},
	})

	Provide(&basic_http.Service{
		ServiceName: "ipecho",
		Url:         "http://ipecho.net/plain",
	})

	Provide(&basic_http.Service{
		ServiceName: "icanhazip",
		Url:         "https://icanhazip.com",
	})
}
