package ip

import (
	"context"
	"net"
	"time"

	"dnsupdater/ip/resolver"
)

// Resolver is a function that gets the ip from a interface name
type NetInterfaceIPResolver func(iface string) (net.IP, error)

func LookupWrapper(service resolver.Service) NetInterfaceIPResolver {
	return func(iface_name string) (net.IP, error) {
		if iface_name == resolver.WAN_IFACE {
			ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
			defer cancel()
			return service.Lookup(ctx)
		}
		return GetInterfaceIP(iface_name)
	}
}
