// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package turn

import (
	
	
	

	
	
)

// RelayAddressGeneratorStatic can be used to return static IP address each time a relay is created.
// This can be used when you have a single static IP address that you want to use.
type RelayAddressGeneratorStatic struct {
	// RelayAddress is the IP returned to the user when the relay is created
	RelayAddress net.IP

	// Address is passed to Listen/ListenPacket when creating the Relay
	Address string

	Net transport.Net
}

// Validate is called on server startup and confirms the RelayAddressGenerator is properly configured.
func ( *RelayAddressGeneratorStatic) () error {
	if .Net == nil {
		var  error
		.Net,  = stdnet.NewNet()
		if  != nil {
			return fmt.Errorf("failed to create network: %w", )
		}
	}

	switch {
	case .RelayAddress == nil:
		return errRelayAddressInvalid
	case .Address == "":
		return errListeningAddressInvalid
	default:
		return nil
	}
}

// AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port
// to populate the allocation response with.
func ( *RelayAddressGeneratorStatic) (
	 string,
	 int,
) (net.PacketConn, net.Addr, error) {
	,  := .Net.ListenPacket(, .Address+":"+strconv.Itoa())
	if  != nil {
		return nil, nil, 
	}

	// Replace actual listening IP with the user requested one of RelayAddressGeneratorStatic
	,  := .LocalAddr().(*net.UDPAddr)
	if ! {
		return nil, nil, errNilConn
	}

	.IP = .RelayAddress

	return , , nil
}

// AllocateConn generates a new Conn to receive traffic on and the IP/Port
// to populate the allocation response with.
func ( *RelayAddressGeneratorStatic) (string, int) (net.Conn, net.Addr, error) {
	return nil, nil, errTODO
}