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"
)

// CreateMultiImageRequest struct to create multi image
type CreateMultiImageRequest struct {
	// Name of the multi image
	// Required: true
	Name string `url:"name" json:"name" validate:"required"`

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

	// Account ID
	// Required: false
	AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
}

// CreateMultiImage creates multi image
func (i Image) CreateMultiImage(ctx context.Context, req CreateMultiImageRequest) (uint64, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return 0, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/image/create_multi_image"

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

	result, err := strconv.ParseUint(string(res), 10, 64)
	if err != nil {
		return 0, err
	}

	return result, nil
}
