package iroh

import (
	
	
	

	
	
	
)

// StaticProvenance is the default provenance string for [StaticLookup] items.
const StaticProvenance = "static_lookup"

// StaticLookup is an immutable [AddressResolver] for addressing information
// fixed at construction time.
//
// The zero value is not usable; create one with [NewStaticLookup],
// [NewStaticLookupWithProvenance], or [StaticLookupFromAddrs]. A StaticLookup is
// safe for concurrent use.
type StaticLookup struct {
	endpoints   map[key.EndpointID]staticInfo
	provenance  string
	lastUpdated uint64
}

type staticInfo struct {
	data dns.EndpointData
}

// NewStaticLookup returns a StaticLookup for infos using [StaticProvenance].
func ( ...dns.EndpointInfo) *StaticLookup {
	return NewStaticLookupWithProvenance(StaticProvenance, ...)
}

// NewStaticLookupWithProvenance returns a StaticLookup for infos whose resolved
// [Item]s report the given provenance.
func ( string,  ...dns.EndpointInfo) *StaticLookup {
	 := &StaticLookup{
		endpoints:   make(map[key.EndpointID]staticInfo, len()),
		provenance:  ,
		lastUpdated: uint64(time.Now().UnixMicro()),
	}
	for ,  := range  {
		.endpoints[.ID] = staticInfo{data: cloneEndpointData(.Data)}
	}
	return 
}

// StaticLookupFromAddrs returns a StaticLookup for endpoint addresses using
// [StaticProvenance].
func ( ...netaddr.EndpointAddr) *StaticLookup {
	 := make([]dns.EndpointInfo, 0, len())
	for ,  := range  {
		 = append(, dns.EndpointInfoFromAddr())
	}
	return NewStaticLookup(...)
}

// Resolve returns the static info for id, or nil if there is no entry.
func ( *StaticLookup) ( context.Context,  key.EndpointID) iter.Seq2[Item, error] {
	if  == nil {
		return nil
	}
	,  := .endpoints[]
	if ! {
		return nil
	}
	 := NewItem(dns.EndpointInfo{ID: , Data: cloneEndpointData(.data)}, .provenance, &.lastUpdated)
	return func( func(Item, error) bool) {
		if .Err() == nil {
			(, nil)
		}
	}
}

func cloneEndpointData( dns.EndpointData) dns.EndpointData {
	 := dns.NewEndpointData(.Addrs()...)
	if  := .UserData();  != nil {
		 := *
		.SetUserData(&)
	}
	return 
}