<commit_before>package v2

import (
	"context"

	apiv2 "github.com/exoscale/egoscale/v2/api"
	papi "github.com/exoscale/egoscale/v2/internal/public-api"
)

// InstancePool represents an Instance Pool.
type InstancePool struct {
	AntiAffinityGroupIDs []string `reset:"anti-affinity-groups"`
	Description          string   `reset:"description"`
	DiskSize             int64
	ElasticIPIDs         []string `reset:"elastic-ips"`
	ID                   string
	IPv6Enabled          bool
	InstanceIDs          []string
	InstanceTypeID       string
	ManagerID            string
	Name                 string
	PrivateNetworkIDs    []string `reset:"private-networks"`
	SSHKey               string   `reset:"ssh-key"`
	SecurityGroupIDs     []string `reset:"security-groups"`
	Size                 int64
	State                string
	TemplateID           string
	UserData             string `reset:"user-data"`

	c    *Client
	zone string
}

func instancePoolFromAPI(i *papi.InstancePool) *InstancePool {
	return &InstancePool{
		AntiAffinityGroupIDs: func() []string {
			ids := make([]string, 0)

			if i.AntiAffinityGroups != nil {
				for _, item := range *i.AntiAffinityGroups {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		Description: papi.OptionalString(i.Description),
		DiskSize:    papi.OptionalInt64(i.DiskSize),
		ElasticIPIDs: func() []string {
			ids := make([]string, 0)

			if i.ElasticIps != nil {
				for _, item := range *i.ElasticIps {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		ID:          papi.OptionalString(i.Id),
		IPv6Enabled: papi.OptionalBool(i.Ipv6Enabled),
		InstanceIDs: func() []string {
			ids := make([]string, 0)

			if i.Instances != nil {
				for _, item := range *i.Instances {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		InstanceTypeID: papi.OptionalString(i.InstanceType.Id),
		ManagerID:      papi.OptionalString(i.Manager.Id),
		Name:           papi.OptionalString(i.Name),
		PrivateNetworkIDs: func() []string {
			ids := make([]string, 0)

			if i.PrivateNetworks != nil {
				for _, item := range *i.PrivateNetworks {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		SSHKey: func() string {
			key := ""
			if i.SshKey != nil {
				key = papi.OptionalString(i.SshKey.Name)
			}
			return key
		}(),
		SecurityGroupIDs: func() []string {
			ids := make([]string, 0)

			if i.SecurityGroups != nil {<commit_msg>v2: fix InstancePool.ManagerID resolution (#479)<commit_after>package v2

import (
	"context"

	apiv2 "github.com/exoscale/egoscale/v2/api"
	papi "github.com/exoscale/egoscale/v2/internal/public-api"
)

// InstancePool represents an Instance Pool.
type InstancePool struct {
	AntiAffinityGroupIDs []string `reset:"anti-affinity-groups"`
	Description          string   `reset:"description"`
	DiskSize             int64
	ElasticIPIDs         []string `reset:"elastic-ips"`
	ID                   string
	IPv6Enabled          bool
	InstanceIDs          []string
	InstanceTypeID       string
	ManagerID            string
	Name                 string
	PrivateNetworkIDs    []string `reset:"private-networks"`
	SSHKey               string   `reset:"ssh-key"`
	SecurityGroupIDs     []string `reset:"security-groups"`
	Size                 int64
	State                string
	TemplateID           string
	UserData             string `reset:"user-data"`

	c    *Client
	zone string
}

func instancePoolFromAPI(i *papi.InstancePool) *InstancePool {
	return &InstancePool{
		AntiAffinityGroupIDs: func() []string {
			ids := make([]string, 0)

			if i.AntiAffinityGroups != nil {
				for _, item := range *i.AntiAffinityGroups {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		Description: papi.OptionalString(i.Description),
		DiskSize:    papi.OptionalInt64(i.DiskSize),
		ElasticIPIDs: func() []string {
			ids := make([]string, 0)

			if i.ElasticIps != nil {
				for _, item := range *i.ElasticIps {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		ID:          papi.OptionalString(i.Id),
		IPv6Enabled: papi.OptionalBool(i.Ipv6Enabled),
		InstanceIDs: func() []string {
			ids := make([]string, 0)

			if i.Instances != nil {
				for _, item := range *i.Instances {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		InstanceTypeID: papi.OptionalString(i.InstanceType.Id),
		ManagerID: func() string {
			if i.Manager != nil {
				return papi.OptionalString(i.Manager.Id)
			}
			return ""
		}(),
		Name: papi.OptionalString(i.Name),
		PrivateNetworkIDs: func() []string {
			ids := make([]string, 0)

			if i.PrivateNetworks != nil {
				for _, item := range *i.PrivateNetworks {
					item := item
					ids = append(ids, *item.Id)
				}
			}

			return ids
		}(),
		SSHKey: func() string {
			key := ""
			if i.SshKey != nil {
				key = papi.OptionalString(i.SshKey.Name)
			}
			return key
		}(),
		SecurityGroupIDs: func() []string {
			ids := make([]string, 0)

			if i.SecurityGroups != nil {
{'fraction_non_alphanumeric': 0.12925969447708577, 'fraction_numerical': 0.007833920877399139, 'mean_word_length': 2.4836289222373806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6845485', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1669, 'n_words': 373}