package image

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

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

// MultiImageAddLinksRequest struct to add links to multi image
type MultiImageAddLinksRequest 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"`
}

// MultiImageAddLinks adds image links to multi image
func (i Image) MultiImageAddLinks(ctx context.Context, req MultiImageAddLinksRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/image/multi_image_add_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
}
