package image

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

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

// MultiImageExportRequest struct to export multi image to a pool
type MultiImageExportRequest struct {
	// ID of the multi image
	// Required: true
	MultiImageID uint64 `url:"multi_image_id" json:"multi_image_id" validate:"required"`

	// Name of the target pool
	// Required: true
	PoolName string `url:"pool_name" json:"pool_name" validate:"required"`

	// Target SEP ID
	// Required: true
	SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
}

// MultiImageExport copies a physical image from multi image to the specified pool
func (i Image) MultiImageExport(ctx context.Context, req MultiImageExportRequest) (uint64, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return 0, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/image/multi_image_export"

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

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

	return result, nil
}
