package acsgroups

import (
	"context"
	"net/http"

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

// UserAddRequest struct to userAdd access group
type UserAddRequest 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"`
}

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

	url := "/sdn/access_group/user_add"

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

	return true, nil
}
