package cmd

import (
	//"os"

	"github.com/SAP/jenkins-library/pkg/config"
	"github.com/spf13/cobra"
)

type testStepOptions struct {
	Param0 string `json:"param0,omitempty"`
	Param1 string `json:"param1,omitempty"`
	Param2 string `json:"param2,omitempty"`
}

var myTestStepOptions testStepOptions
var testStepStepConfigJSON string

// TestStepCommand Test description
func TestStepCommand() *cobra.Command {
	metadata := testStepMetadata()
	var createTestStepCmd = &cobra.Command{
		Use:   "testStep",
		Short: "Test description",
		Long: `Long Test description`,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			return PrepareConfig(cmd, &metadata, "testStep", &myTestStepOptions, openPiperFile)
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			return testStep(myTestStepOptions)
		},
	}

	addTestStepFlags(createTestStepCmd)
	return createTestStepCmd
}

func addTestStepFlags(cmd *cobra.Command) {
	cmd.Flags().StringVar(&myTestStepOptions.Param0, "param0", "val0", "param0 description")
	cmd.Flags().StringVar(&myTestStepOptions.Param1, "param1", os.Getenv("PIPER_param1"), "param1 description")
	cmd.Flags().StringVar(&myTestStepOptions.Param2, "param2", os.Getenv("PIPER_param2"), "param1 description")

	cmd.MarkFlagRequired("param0")
	cmd.MarkFlagRequired("param2")
}

// retrieve step metadata
func testStepMetadata() config.StepData {
	var theMetaData = config.StepData{
		Spec: config.StepSpec{
			Inputs: config.StepInputs{
				Parameters: []config.StepParameters{
					{
						Name:      "param0",
						Scope:     []string{"GENERAL","PARAMETERS",},
						Type:      "string",
						Mandatory: true,
					},
					{
						Name:      "param1",
						Scope:     []string{"PARAMETERS",},
						Type:      "string",
						Mandatory: false,
					},
					{
						Name:      "param2",
						Scope:     []string{"PARAMETERS",},
						Type:      "string",
						Mandatory: true,
					},
				},
			},
		},
	}
	return theMetaData
}
