package object_test

import (
	"testing"

	"github.com/scaleway/scaleway-cli/v2/core"
	"github.com/scaleway/scaleway-cli/v2/internal/namespaces/object/v1"
	"github.com/scaleway/scaleway-sdk-go/scw"
	"github.com/stretchr/testify/require"
)

func Test_ConfigGet(t *testing.T) {
	client, err := scw.NewClient(
		scw.WithAuth(
			"SCWXXXXXXXXXXXXXXXXX",
			"11111111-1111-1111-1111-111111111111",
		),
		scw.WithDefaultOrganizationID("11111111-1111-1111-1111-111111111111"),
		scw.WithDefaultProjectID("11111111-1111-1111-1111-111111111111"),
		scw.WithDefaultZone(scw.ZoneFrPar1),
		scw.WithDefaultRegion(scw.RegionFrPar),
	)
	require.NoError(t, err)

	t.Run("Default", func(t *testing.T) {
		t.Run("rclone", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=rclone",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))

		t.Run("mc", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=mc",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))

		t.Run("s3cmd", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=s3cmd",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))
	})

	t.Run("With region", func(t *testing.T) {
		t.Run("rclone", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=rclone region=nl-ams",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))

		t.Run("mc", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=mc region=nl-ams",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))

		t.Run("s3cmd", core.Test(&core.TestConfig{
			Commands: object.GetCommands(),
			Cmd:      "scw object config get type=s3cmd region=nl-ams",
			Check: core.TestCheckCombine(
				core.TestCheckGolden(),
				core.TestCheckExitCode(0),
			),
			Client: client,
		}))
	})
}
