func (e *ENIIP) GetType() string {
	return ResourceTypeENIIP
}
GetType return type name
package types
import (
	"fmt"
	"net"
	"strings"
	terwayIP "github.com/AliyunContainerService/terway/pkg/ip"
	"github.com/AliyunContainerService/terway/pkg/utils"
	"github.com/AliyunContainerService/terway/rpc"
)
type InternetChargeType string
const (
	PayByBandwidth = InternetChargeType("PayByBandwidth")
	PayByTraffic   = InternetChargeType("PayByTraffic")
)
type EIPInstanceType string
const EIPInstanceTypeNetworkInterface EIPInstanceType = "NetworkInterface"
const (
	ResourceTypeVeth  = "veth"
	ResourceTypeENI   = "eni"
	ResourceTypeENIIP = "eniIp"
	ResourceTypeEIP   = "eip"
)
const (
	VSwitchSelectionPolicyRandom  = "random"
	VSwitchSelectionPolicyOrdered = "ordered"
)
type IPStack string
const (
	IPStackIPv4 IPStack = "ipv4"
	IPStackDual IPStack = "dual"
	IPStackIPv6 IPStack = "ipv6"
)
type IPFamily struct {
	IPv4 bool
	IPv6 bool
}
func NewIPFamilyFromIPStack(ipStack IPStack) *IPFamily {
	f := &IPFamily{}
	switch ipStack {
	case IPStackIPv4:
		f.IPv4 = true
	case IPStackDual:
		f.IPv4 = true
		f.IPv6 = true
	case IPStackIPv6:
		f.IPv6 = true
	}
	return f
}
type IPSet struct {
	IPv4 net.IP
	IPv6 net.IP
}
func (i *IPSet) String() string {
	var result []string
	if i.IPv4 != nil {
		result = append(result, i.IPv4.String())
	}
	if i.IPv6 != nil {
		result = append(result, i.IPv6.String())
	}
	return strings.Join(result, "-")
}
func (i *IPSet) ToRPC() *rpc.IPSet {
	var ipv4, ipv6 string
	if i.IPv4 != nil {
		ipv4 = i.IPv4.String()
	}
	if i.IPv6 != nil {
		ipv6 = i.IPv6.String()
	}
	return &rpc.IPSet{
		IPv4: ipv4,
		IPv6: ipv6,
	}
}
func (i *IPSet) SetIP(str string) *IPSet {
	ip := net.ParseIP(str)
	if ip == nil {
		return i
	}
	if terwayIP.IPv6(ip) {
		i.IPv6 = ip
		return i
	}
	i.IPv4 = ip
	return i
}
func (i *IPSet) GetIPv4() string {
	if i.IPv4 == nil {
		return ""
	}
	return i.IPv4.String()
}
func (i *IPSet) GetIPv6() string {
	if i.IPv6 == nil {
		return ""
	}
	return i.IPv6.String()
}
func MergeIPs(a, b []net.IP) []IPSet {
	result := make([]IPSet, utils.Max(len(a), len(b)))
	for i, ip := range a {
		result[i].IPv4 = ip
	}
	for i, ip := range b {
		result[i].IPv6 = ip
	}
	return result
}
type IPNetSet struct {
	IPv4 *net.IPNet
	IPv6 *net.IPNet
}
func (i *IPNetSet) ToRPC() *rpc.IPSet {
	var ipv4, ipv6 string
	if i.IPv4 != nil {
		ipv4 = i.IPv4.String()
	}
	if i.IPv6 != nil {
		ipv6 = i.IPv6.String()
	}
	return &rpc.IPSet{
		IPv4: ipv4,
		IPv6: ipv6,
	}
}
func (i *IPNetSet) String() string {
	var result []string
	if i.IPv4 != nil {
		result = append(result, i.IPv4.String())
	}
	if i.IPv6 != nil {
		result = append(result, i.IPv6.String())
	}
	return strings.Join(result, "-")
}
func (i *IPNetSet) SetIPNet(str string) *IPNetSet {
	ip, ipNet, err := net.ParseCIDR(str)
	if err != nil {
		return i
	}
	if ip == nil {
		return i
	}
	if terwayIP.IPv6(ip) {
		i.IPv6 = ipNet
		return i
	}
	i.IPv4 = ipNet
	return i
}
type ENI struct {
	ID               string
	MAC              string
	MaxIPs           int
	SecurityGroupIDs []string
	Trunk bool
	PrimaryIP IPSet
	GatewayIP IPSet
	VSwitchCIDR IPNetSet
	VSwitchID string
}
func (e *ENI) GetResourceID() string {
	return e.MAC
}
func (e *ENI) GetType() string {
	return ResourceTypeENI
}
func (e *ENI) ToResItems() []ResourceItem {
	return []ResourceItem{
		{
			Type:   e.GetType(),
			ID:     e.GetResourceID(),
			ENIID:  e.ID,
			ENIMAC: e.MAC,
			IPv4:   e.PrimaryIP.GetIPv4(),
			IPv6:   e.PrimaryIP.GetIPv6(),
		},
	}
}
type ENIIP struct {
	ENI   *ENI
	IPSet IPSet
}
func (e *ENIIP) GetResourceID() string {
	return fmt.Sprintf("%s.%s", e.ENI.GetResourceID(), e.IPSet.String())
}