package user

import (
	"context"
	"net/http"

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

// CreateRequest struct for creating a user.
type CreateRequest struct {
	// ID of user.
	// Required: true
	Username string `url:"username" json:"username" validate:"required"`

	// Email address of the user.
	// Required: true
	EmailAddress string `url:"emailaddress" json:"emailaddress" validate:"required"`

	// Password of user
	// Required: true
	Password string `url:"password" json:"password" validate:"required"`

	// List of apiaccess groups this user belongs to.
	// Required: false
	APIAccess []uint64 `url:"apiaccess,omitempty" json:"apiaccess,omitempty"`

	// Provider of user
	// one of: bvs, decs3o
	// Required: false
	Provider string `url:"provider,omitempty" json:"provider,omitempty" validate:"omitempty,userProvider"`
}

// Create creates a user.
func (u User) Create(ctx context.Context, req CreateRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/user/create"

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

	return string(res), nil
}
