package core_test

import (
	"github.com/pivotal-cf-experimental/destiny/core"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("AZs", func() {
	It("returns a slice of AZs given a number of AZs desired", func() {
		azs := core.AZs(2)
		Expect(azs).To(Equal([]string{"z1", "z2"}))
	})
})
func consulInstanceGroup(config ConfigV2) (core.InstanceGroup, error) {
	persistentDiskType := config.PersistentDiskType
	azs := config.AZs
	vmType := config.VMType
	totalNodes := 0
	for _, az := range azs {
		totalNodes += az.Nodes
	}

	if persistentDiskType == "" {
		persistentDiskType = "default"
	}

	if vmType == "" {
		vmType = "default"
	}

	consulInstanceGroupStaticIPs, err := consulInstanceGroupStaticIPs(azs)
	if err != nil {
		return core.InstanceGroup{}, err
	}

	return core.InstanceGroup{
		Instances: totalNodes,
		Name:      "consul",
		AZs:       core.AZs(len(azs)),
		Networks: []core.InstanceGroupNetwork{
			{
				Name:      "private",
				StaticIPs: consulInstanceGroupStaticIPs,
			},
		},
		VMType:             vmType,
		Stemcell:           "linux",
		PersistentDiskType: persistentDiskType,
		Jobs: []core.InstanceGroupJob{
			{
				Name:    "consul_agent",
				Release: "consul",
			},
		},
		Properties: &core.JobProperties{
			Consul: &core.JobPropertiesConsul{
				Agent: core.JobPropertiesConsulAgent{
					Mode:     "server",
					LogLevel: "info",
					Services: core.JobPropertiesConsulAgentServices{
						"router": core.JobPropertiesConsulAgentService{
							Name: "gorouter",
							Check: &core.JobPropertiesConsulAgentServiceCheck{
								Name:     "router-check",
								Script:   "/var/vcap/jobs/router/bin/script",
								Interval: "1m",
							},
							Tags: []string{"routing"},
						},
						"cloud_controller": core.JobPropertiesConsulAgentService{},
					},
				},
			},
		},
	}, nil
}