package compute

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

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

// ChangeMTURequest struct to change MTU for a compute
type ChangeMTURequest struct {
	// ID of compute instance
	// Required: true
	ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`

	// Interface name or MAC address
	// Required: true
	Interface string `url:"interface" json:"interface" validate:"required"`

	// Maximum transmission unit
	// Required: true
	MTU uint64 `url:"mtu" json:"mtu" validate:"required" validate:"omitempty,mtu"`
}

// ChangeMTU change MTU for compute instance
func (c Compute) ChangeMTU(ctx context.Context, req ChangeMTURequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/compute/change_mtu"

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

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

	return result, nil
}
