package node

import (
	"context"
	"net/http"

	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)

// InstallRequest struct to install a node
type InstallRequest struct {
	// Node name
	// Required: true
	Name string `url:"name" json:"name" validate:"required"`

	// Node roles
	// Required: true
	Roles []string `url:"roles" json:"roles" validate:"required"`

	// OS version
	// Required: true
	OSVersion string `url:"os_version" json:"os_version" validate:"required"`

	// OS user
	// Required: false
	OSUser string `url:"os_user,omitempty" json:"os_user,omitempty"`

	// OS user password
	// Required: true
	OSUserPassword string `url:"os_user_password" json:"os_user_password" validate:"required"`

	// Backplane IP address
	// Required: true
	BackplaneIP string `url:"backplane_ip" json:"backplane_ip" validate:"required"`

	// Management IP address
	// Required: true
	ManagementIP string `url:"management_ip" json:"management_ip" validate:"required"`

	// VX backend IP address
	// Required: true
	VXBackendIP string `url:"vxbackend_ip" json:"vxbackend_ip" validate:"required"`

	// Gateway management IP address
	// Required: true
	GWMgmtIP string `url:"gw_mgmt_ip" json:"gw_mgmt_ip" validate:"required"`

	// IPMI address
	// Required: true
	IPMIAddress string `url:"ipmi_address" json:"ipmi_address" validate:"required"`

	// IPMI user
	// Required: true
	IPMIUser string `url:"ipmi_user" json:"ipmi_user" validate:"required"`

	// IPMI password
	// Required: true
	IPMIPassword string `url:"ipmi_password" json:"ipmi_password" validate:"required"`
}

// Install installs a node
func (n Node) Install(ctx context.Context, req InstallRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/install"

	res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
	if err != nil {
		return "", err
	}

	return string(res), nil
}
