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

package ice

import (
	
	
)

// CandidateHost is a candidate of type host.
type CandidateHost struct {
	candidateBase

	network string
}

// CandidateHostConfig is the config required to create a new CandidateHost.
type CandidateHostConfig struct {
	CandidateID       string
	Network           string
	Address           string
	Port              int
	Component         uint16
	Priority          uint32
	Foundation        string
	TCPType           TCPType
	IsLocationTracked bool
}

// NewCandidateHost creates a new host candidate.
func ( *CandidateHostConfig) (*CandidateHost, error) {
	 := .CandidateID

	if  == "" {
		 = globalCandidateIDGenerator.Generate()
	}

	 := &CandidateHost{
		candidateBase: candidateBase{
			id:                    ,
			address:               .Address,
			candidateType:         CandidateTypeHost,
			component:             .Component,
			port:                  .Port,
			tcpType:               .TCPType,
			foundationOverride:    .Foundation,
			priorityOverride:      .Priority,
			remoteCandidateCaches: map[AddrPort]Candidate{},
			isLocationTracked:     .IsLocationTracked,
		},
		network: .Network,
	}

	if !strings.HasSuffix(.Address, ".local") {
		,  := netip.ParseAddr(.Address)
		if  != nil {
			return nil, 
		}

		if  := .setIPAddr();  != nil {
			return nil, 
		}
	} else {
		// Until mDNS candidate is resolved assume it is UDPv4
		.candidateBase.networkType = NetworkTypeUDP4
	}

	return , nil
}

func ( *CandidateHost) ( netip.Addr) error {
	,  := determineNetworkType(.network, )
	if  != nil {
		return 
	}

	.candidateBase.networkType = 
	.candidateBase.resolvedAddr = createAddr(, , .port)

	return nil
}