package compute

import (
	"context"
	"net/http"
	"strings"

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

// MigrateStorageAbortRequest struct to abort migration
type MigrateStorageAbortRequest struct {
	// ID of the compute instance
	// Required: true
	ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`

	// Status check
	// Default: false
	// Required: false
	StatusCheck bool `url:"statusCheck" json:"statusCheck"`
}

// MigrateStorageAbort aborts complex compute migration job
func (c Compute) MigrateStorageAbort(ctx context.Context, req MigrateStorageAbortRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/compute/migrateStorageAbort"

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

	result := strings.ReplaceAll(string(res), "\"", "")

	return result, nil
}
