package compute

import (
	"context"
	"net/http"
	"strconv"
)

type wrapperRaiseDownRequest struct {
	AsyncMode bool `url:"asyncMode"`
}

// RaiseDown starting all computes in "DOWN" tech status
func (c Compute) RaiseDown(ctx context.Context) (bool, error) {
	reqWrapped := wrapperRaiseDownRequest{AsyncMode: false}

	url := "/cloudbroker/compute/raiseDown"

	res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
	if err != nil {
		return false, err
	}

	result, err := strconv.ParseBool(string(res))
	if err != nil {
		return false, err
	}

	return result, nil
}

// RaiseDownAsync starting all computes in "DOWN" tech status with AsyncMode
func (c Compute) RaiseDownAsync(ctx context.Context) (string, error) {
	reqWrapped := wrapperRaiseDownRequest{AsyncMode: true}

	url := "/cloudbroker/compute/raiseDown"

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

	return string(res), nil
}
