package image

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

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

// MultiImageDelLinksRequest struct to delete links from multi image
type MultiImageDelLinksRequest struct {
	// ID of the multi image
	// Required: true
	ImageID uint64 `url:"image_id" json:"image_id" validate:"required"`

	// IDs of real images
	// Required: true
	TargetIDs []uint64 `url:"target_ids" json:"target_ids" validate:"required"`
}

// MultiImageDelLinks removes image links from multi image
func (i Image) MultiImageDelLinks(ctx context.Context, req MultiImageDelLinksRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/image/multi_image_del_links"

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

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

	return result, nil
}
