package sakuracloud

import (
	"context"
	"errors"
	"fmt"
	"testing"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
	"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
	"github.com/sacloud/libsacloud/v2/sacloud"
)

func TestAccSakuraCloudPrivateHost_basic(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudIconDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_basic, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand),
					resource.TestCheckResourceAttr(resourceName, "description", "description"),
					resource.TestCheckResourceAttr(resourceName, "class", "dynamic"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
					resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"),
					resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"),
					resource.TestCheckResourceAttrPair(
						resourceName, "id",
						"sakuracloud_server.foobar", "private_host_id",
					),
					resource.TestCheckResourceAttrPair(
						resourceName, "icon_id",
						"sakuracloud_icon.foobar", "id",
					),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_update, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand+"-upd"),
					resource.TestCheckResourceAttr(resourceName, "description", "description-upd"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "0"),
					resource.TestCheckResourceAttr(resourceName, "icon_id", ""),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
		},
	})
}

func TestAccSakuraCloudPrivateHost_windows(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudIconDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_windows, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand),
					resource.TestCheckResourceAttr(resourceName, "description", "description"),
					resource.TestCheckResourceAttr(resourceName, "class", "ms_windows"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
					resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"),
					resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
		},
	})
}

func TestAccSakuraCloudPrivateHost_destroyWithRunningServer(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_destroy, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
				),
			},
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_destroyed, rand),
				Check: resource.ComposeTestCheckFunc(
					resource.TestCheckResourceAttr(
						"sakuracloud_server.foobar", "private_host_id", ""),
				),
			},
		},
	})
}

func testCheckSakuraCloudPrivateHostExists(n string, privateHost *sacloud.PrivateHost) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[n]

		if !ok {
			return fmt.Errorf("not found: %s", n)
		}

		if rs.Primary.ID == "" {
			return errors.New("no PrivateHost ID is set")
		}

		client := testAccProvider.Meta().(*APIClient)
		zone := rs.Primary.Attributes["zone"]
		phOp := sacloud.NewPrivateHostOp(client)

		foundPrivateHost, err := phOp.Read(context.Background(), zone, sakuraCloudID(rs.Primary.ID))
		if err != nil {
			return err
		}

		if foundPrivateHost.ID.String() != rs.Primary.ID {
			return fmt.Errorf("not found PrivateHost: %s", rs.Primary.ID)
		}
		*privateHost = *foundPrivateHost

		return nil
	}
}

func testCheckSakuraCloudPrivateHostDestroy(s *terraform.State) error {
	client := testAccProvider.Meta().(*APIClient)
	phOp := sacloud.NewPrivateHostOp(client)

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "sakuracloud_private_host" {
			continue
		}
		if rs.Primary.ID == "" {
			continue
		}

		zone := rs.Primary.Attributes["zone"]
		_, err := phOp.Read(context.Background(), zone, sakuraCloudID(rs.Primary.ID))
		if err == nil {
			return fmt.Errorf("still exists PrivateHost: %s", rs.Primary.ID)
		}
	}

	return nil
}

var testAccSakuraCloudPrivateHost_basic = `
resource "sakuracloud_server" "foobar" {
  name            = "{{ .arg0 }}"
  private_host_id = sakuracloud_private_host.foobar.id

  force_shutdown = true
}

resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
  description = "description"
  tags        = ["tag1", "tag2"]
  icon_id     = sakuracloud_icon.foobar.id
}

resource "sakuracloud_icon" "foobar" {
  name          = "description"
  base64content = "iVBORw0KGgoAAAANSUh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tnJk3/e1fDoI6vKysoqK8pbP/q323RDdi2hq/0ysHGyAwopU4lEfNXKlWo0Hx069MDSZcePHy8MBk3Tk0ylTnd1+wsKTNMERLUGlLtA1A3jyNEjagIKgsFk0gEM5NCSOst0+wEjAEvHtktKSuoeWAIAX3311f11Szs7OydcPtFwGYDp0sagWhoa7K4G5/f71TfHskEVdHXMn6M16CzLDcRkWfaM6dWm6QGAjZs2t7W1X1JeYRgGMzERMxOnNYa5O8mkrmkzr50JAKlUqq29Le2VQ0sACmYmIvU1OwAmLKt6ejUAyJTcu3dfQTCoaZqUkgEoY0ODvKRMSWbLsjo6O2fPmbuw9nYAOHjw4KdHjhqGoRqgLFpS6oNOE84JRDLVX1FeDgBd3V0pIrfLxZn5GGLMrE40y7YTCcula7W3167++c+UzfNbtzGRK+ObxR1RZyJARPUpNxBzPBYDAE3ThCYkETMjIPMQdwCwbNttGItqb6uqrJo2deqMGTVK8qWXX969+92SsjAi5hRF1BkQKJ3REUDXtE+PHL3ppptCoVBpcXFXVzdJqerFWWNmKaVt2T9YWldf
}`

var testAccSakuraCloudPrivateHost_update = `
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}-upd"
  description = "description-upd"
}
`

var testAccSakuraCloudPrivateHost_windows = `
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
  class       = "ms_windows"
  description = "description"
  tags        = ["tag1", "tag2"]
}
`

var testAccSakuraCloudPrivateHost_destroy = `
resource "sakuracloud_server" "foobar" {
  name            = "{{ .arg0 }}"
  private_host_id = sakuracloud_private_host.foobar.id
  network_interface {
    upstream = "shared"
  }

  force_shutdown = true
}
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
}
`

var testAccSakuraCloudPrivateHost_destroyed = `
resource "sakuracloud_server" "foobar" {
  name = "{{ .arg0 }}"

  network_interface {
    upstream = "shared"
  }

  force_shutdown = true
}
`
// Copyright 2016-2021 terraform-provider-sakuracloud authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sakuracloud

import (
	"context"
	"errors"
	"fmt"
	"testing"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
	"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
	"github.com/sacloud/libsacloud/v2/sacloud"
)

func TestAccSakuraCloudPrivateHost_basic(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudIconDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_basic, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand),
					resource.TestCheckResourceAttr(resourceName, "description", "description"),
					resource.TestCheckResourceAttr(resourceName, "class", "dynamic"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
					resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"),
					resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"),
					resource.TestCheckResourceAttrPair(
						resourceName, "id",
						"sakuracloud_server.foobar", "private_host_id",
					),
					resource.TestCheckResourceAttrPair(
						resourceName, "icon_id",
						"sakuracloud_icon.foobar", "id",
					),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_update, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand+"-upd"),
					resource.TestCheckResourceAttr(resourceName, "description", "description-upd"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "0"),
					resource.TestCheckResourceAttr(resourceName, "icon_id", ""),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
		},
	})
}

func TestAccSakuraCloudPrivateHost_windows(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudIconDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_windows, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
					resource.TestCheckResourceAttr(resourceName, "name", rand),
					resource.TestCheckResourceAttr(resourceName, "description", "description"),
					resource.TestCheckResourceAttr(resourceName, "class", "ms_windows"),
					resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
					resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"),
					resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"),
					resource.TestCheckResourceAttrSet(resourceName, "hostname"),
				),
			},
		},
	})
}

func TestAccSakuraCloudPrivateHost_destroyWithRunningServer(t *testing.T) {
	skipIfZoneIsDummy(t)

	resourceName := "sakuracloud_private_host.foobar"
	rand := randomName()

	var privateHost sacloud.PrivateHost
	resource.ParallelTest(t, resource.TestCase{
		PreCheck:          func() { testAccPreCheck(t) },
		ProviderFactories: testAccProviderFactories,
		CheckDestroy: resource.ComposeTestCheckFunc(
			testCheckSakuraCloudPrivateHostDestroy,
			testCheckSakuraCloudServerDestroy,
		),
		Steps: []resource.TestStep{
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_destroy, rand),
				Check: resource.ComposeTestCheckFunc(
					testCheckSakuraCloudPrivateHostExists(resourceName, &privateHost),
				),
			},
			{
				Config: buildConfigWithArgs(testAccSakuraCloudPrivateHost_destroyed, rand),
				Check: resource.ComposeTestCheckFunc(
					resource.TestCheckResourceAttr(
						"sakuracloud_server.foobar", "private_host_id", ""),
				),
			},
		},
	})
}

func testCheckSakuraCloudPrivateHostExists(n string, privateHost *sacloud.PrivateHost) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		rs, ok := s.RootModule().Resources[n]

		if !ok {
			return fmt.Errorf("not found: %s", n)
		}

		if rs.Primary.ID == "" {
			return errors.New("no PrivateHost ID is set")
		}

		client := testAccProvider.Meta().(*APIClient)
		zone := rs.Primary.Attributes["zone"]
		phOp := sacloud.NewPrivateHostOp(client)

		foundPrivateHost, err := phOp.Read(context.Background(), zone, sakuraCloudID(rs.Primary.ID))
		if err != nil {
			return err
		}

		if foundPrivateHost.ID.String() != rs.Primary.ID {
			return fmt.Errorf("not found PrivateHost: %s", rs.Primary.ID)
		}
		*privateHost = *foundPrivateHost

		return nil
	}
}

func testCheckSakuraCloudPrivateHostDestroy(s *terraform.State) error {
	client := testAccProvider.Meta().(*APIClient)
	phOp := sacloud.NewPrivateHostOp(client)

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "sakuracloud_private_host" {
			continue
		}
		if rs.Primary.ID == "" {
			continue
		}

		zone := rs.Primary.Attributes["zone"]
		_, err := phOp.Read(context.Background(), zone, sakuraCloudID(rs.Primary.ID))
		if err == nil {
			return fmt.Errorf("still exists PrivateHost: %s", rs.Primary.ID)
		}
	}

	return nil
}

var testAccSakuraCloudPrivateHost_basic = `
resource "sakuracloud_server" "foobar" {
  name            = "{{ .arg0 }}"
  private_host_id = sakuracloud_private_host.foobar.id

  force_shutdown = true
}

resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
  description = "description"
  tags        = ["tag1", "tag2"]
  icon_id     = sakuracloud_icon.foobar.id
}

resource "sakuracloud_icon" "foobar" {
  name          = "description"
  base64content = "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAACdBJREFUWMPNmHtw1NUVx8+5v9/+9rfJPpJNNslisgmIiCCgDQZR5GWnilUDPlpUqjOB2mp4qGM7tVOn/yCWh4AOVUprHRVB2+lMa0l88Kq10iYpNYPWkdeAmFjyEJPN7v5+v83ec/rH3Q1J2A2Z1hnYvz755ZzzvXPPveeee/GbC24FJmZGIYD5QgPpTBIAAICJLgJAwUQMAIDMfOEBUQchgJmAEC8CINLPThpfFCAG5orhogCBQiAAEyF8PQCATEQyxQzMzFIi4Ojdv86UEVF/f38ymezv7yciANR0zXAZhuHSdR0RRxNHZyJEBERmQvhfAAABIJlMJhIJt9t9TXX11GlTffleQGhvbz/4YeuRw4c13ZWfnycQR9ACQEShAyIxAxEKMXoAIVQ6VCzHcSzLmj937qqVK8aNrYKhv4bGxue3bvu8rc3n9+ualisyMzOltMjYccBqWanKdD5gBgAppZNMJhKJvlgs1heLxWL3fPfutU8/VVhYoGx7e3uJyOVyAcCEyy6bN2d266FDbW3thsuFI0gA4qy589PTOJC7EYEBbNu2ElYg4J9e/Y3p1dWBgN+l67csWKBC/mrbth07dnafOSMQp0y58pEVK2tm1ABAW9vn93zvgYRl5+XlAXMuCbxh3o3MDMyIguE8wADRaJ/H7Vp873119y8JBALDsrN8xcpXX3utoKDQNE1iiEV7ieSzmzYuXrwYAH7z4m83bNoc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7tKx0wHD16tVPPvkkAIDQvV6fz+fNz/emXzyAYVS5yqSsqLh4UM8GwwAFmqZ54sSJXY2NJSUlkyZNAgDTNL1er/Jvb29/uL7+1y++VFQcKg2PCYVCfr/XND1C01QnnytydkDECVdcqdpqtXGGgcqulHTmy+54PH71VdNunD+/sqoSEaPRaEtzy569exO2UxQM5nm9ynpQgrIEPA8w42UTJ6dLEkNWUI0KMTu2E4v3xftiSccGAKHpnrw8v8/vyfPoug4Zv1xxRgOIoDNJQAEMmfo9HNT9DxFN03QbRrCwCNQjHAp1gVc2mQKbM86oAFCA0GDQnSEXqMcGwPQjmND1zGgEAFBmNOeNMzIQSZ0GXvJHuJedPXRkLhiN+2hAVxUdz77yXWDQUdMGFUa40DC4Y/ya5vz/BMEkmVm9dl94QPwvNJB+oilXgHEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMDItMTBUMjE6MDg6MzMtMDg6MDB4P0OtAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE2LTAyLTEwVDIxOjA4OjMzLTA4OjAwCWL7EQAAAABJRU5ErkJggg=="
}`

var testAccSakuraCloudPrivateHost_update = `
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}-upd"
  description = "description-upd"
}
`

var testAccSakuraCloudPrivateHost_windows = `
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
  class       = "ms_windows"
  description = "description"
  tags        = ["tag1", "tag2"]
}
`

var testAccSakuraCloudPrivateHost_destroy = `
resource "sakuracloud_server" "foobar" {
  name            = "{{ .arg0 }}"
  private_host_id = sakuracloud_private_host.foobar.id
  network_interface {
    upstream = "shared"
  }

  force_shutdown = true
}
resource "sakuracloud_private_host" "foobar" {
  name        = "{{ .arg0 }}"
}
`

var testAccSakuraCloudPrivateHost_destroyed = `
resource "sakuracloud_server" "foobar" {
  name = "{{ .arg0 }}"

  network_interface {
    upstream = "shared"
  }

  force_shutdown = true
}
`
