package user

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

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

// SetDataRequest struct for setting extra user information.
type SetDataRequest struct {
	// Data to set to user in json format
	// Required: true
	Data string `url:"data" json:"data" validation:"required"`
}

// SetData sets extra user information.
func (u User) SetData(ctx context.Context, req SetDataRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudapi/user/setData"

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