package compute

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

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

// SetCPUAlignmentProfileRequest struct to set CPU alignment profile for computes
type SetCPUAlignmentProfileRequest struct {
	// IDs of the compute instances
	// Required: true
	ComputeIDs []int64 `url:"compute_ids" json:"compute_ids" validate:"min=1"`

	// CPU alignment profile name
	// Required: true
	CPUAlignmentProfile string `url:"cpu_alignment_profile" json:"cpu_alignment_profile" validate:"required"`
}

// SetCPUAlignmentProfile sets CPU alignment profile for computes
func (c Compute) SetCPUAlignmentProfile(ctx context.Context, req SetCPUAlignmentProfileRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/compute/set_cpu_alignment_profile"

	res, err := c.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
}
