package compute

import (
	"context"
	"encoding/json"
	"net/http"

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

// CloneAbortRequest struct to abort a compute clone
type CloneAbortRequest struct {
	// ID of compute instance
	// Required: true
	ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}

// CloneAbort aborts a compute clone
func (c Compute) CloneAbort(ctx context.Context, req CloneAbortRequest) ([]RecordCloneAbort, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/compute/clone_abort"

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

	result := make([]RecordCloneAbort, 0)

	err = json.Unmarshal(res, &result)
	if err != nil {
		return nil, err
	}

	return result, nil
}
