package compute

import (
	"context"
	"net/http"

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

// AbortSharedSnapshotMergeRequest struct to abort shared snapshots merge
type AbortSharedSnapshotMergeRequest struct {
	// ID of the compute
	// Required: true
	ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`

	// Label of the snapshot
	// Required: true
	Label string `url:"label" json:"label" validate:"required"`
}

type wrapperAbortSharedSnapshotMergeRequest struct {
	AbortSharedSnapshotMergeRequest
	AsyncMode bool `url:"asyncMode"`
}

// AbortSharedSnapshotMerge shared snapshots merge abort
func (c Compute) AbortSharedSnapshotMerge(ctx context.Context, req AbortSharedSnapshotMergeRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	reqWrapped := wrapperAbortSharedSnapshotMergeRequest{
		AbortSharedSnapshotMergeRequest: req,
		AsyncMode:                       false,
	}

	url := "/cloudapi/compute/abort_shared_snapshot_merge"

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

	return string(res), nil
}

// AbortSharedSnapshotMergeAsync shared snapshots merge abort in async mode
func (c Compute) AbortSharedSnapshotMergeAsync(ctx context.Context, req AbortSharedSnapshotMergeRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	reqWrapped := wrapperAbortSharedSnapshotMergeRequest{
		AbortSharedSnapshotMergeRequest: req,
		AsyncMode:                       true,
	}

	url := "/cloudapi/compute/abort_shared_snapshot_merge"

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

	return string(res), nil
}
