package data

import (
	"fmt"
	"net"
)

func (d *IpDb) Query(ipArg string) (map[string]any, *net.IPNet, error) {
	ip := net.ParseIP(ipArg)
	if ip == nil {
		return nil, nil, fmt.Errorf("invalid IP: %s", ipArg)
	}
	// Get data of IP.
	anyData := make(map[string]any)
	recordNet, ok, err := d.r.LookupNetwork(ip, &anyData)
	if err != nil {
		return nil, nil, err
	}
	if !ok {
		return nil, nil, fmt.Errorf("IP not found: %s", ipArg)
	}
	return anyData, recordNet, nil
}
