package flags

import (
	"fmt"
	"net"
)

func (flags *Flags) parseAddressPort() (err error) {

	// Ensure that address field is not empty
	if flags.Vars.Address == "" {
		return fmt.Errorf("Address cannot be empty")
	}

	// Ensure that address field is valid IP address
	if net.ParseIP(flags.Vars.Address) == nil {
		return fmt.Errorf("GloVars must be a valid IP address")
	}

	// Ensure that port field is not empty
	if flags.Vars.Port == 0 {
		return fmt.Errorf("Port cannot be empty")
	}

	// Ensure that port field is within the valid range
	if flags.Vars.Port < 1 || flags.Vars.Port > 65535 {
		return fmt.Errorf("Port must be between 1 and 65535")
	}

	return nil

}
