package apiaccess

import (
	"context"
	"encoding/json"
	"net/http"

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

// UserListRequest struct for getting a list of users currently included in the specified group.
type UserListRequest struct {
	// APIAccess group ID
	// Required: true
	APIAccessID uint64 `url:"apiaccess_id" json:"apiaccess_id" validate:"required"`

	// Page number
	// Required: false
	Page uint64 `url:"page,omitempty" json:"page,omitempty"`

	// Page size
	// Required: false
	Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}

// UserList gets a list of users currently included in the specified group.
func (a APIAccess) UserList(ctx context.Context, req UserListRequest) ([]string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/apiaccess/userList"

	list := make([]string, 0)

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

	err = json.Unmarshal(res, &list)
	if err != nil {
		return nil, err
	}

	return list, nil
}
