package k8ci

import (
	"context"
	"net/http"

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

// AccessAddRequest struct for adding permission to access to account for a k8ci
type AccessAddRequest struct {
	// ID of the K8 catalog item to add access for
	// Required: true
	K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`

	// Account ID to add to the sharedWith access list
	// Required: true
	AccountId uint64 `url:"accountId" json:"accountId" validate:"required"`
}

// Add accountId to sharedWith access list for k8ci.
func (k K8CI) AccessAdd(ctx context.Context, req AccessAddRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/k8ci/accessAdd"

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

	return string(res), nil
}
