package acsgroups

import (
	"context"
	"net/http"

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

// UserUpdateRoleRequest struct to userUpdateRole access group
type UserUpdateRoleRequest struct {
	// Comment of the access group
	// Required: true
	GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`

	// Access group role ID
	// Required: true
	AccessGroupRoleID string `url:"access_group_role_id" json:"access_group_role_id" validate:"required"`

	// User ID
	// Required: true
	UserID string `url:"user_id" json:"user_id" validate:"required"`
}

// UserUpdateRole a access groups
func (i AccessGroups) UserUpdateRole(ctx context.Context, req UserUpdateRoleRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/access_group/update_role"

	_, err = i.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
	if err != nil {
		return false, err
	}

	return true, nil
}
