package node

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

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

// GetSSHIdentityRequest struct to get node ssh information
type GetSSHIdentityRequest struct {
	// Node ID
	// Required: true
	NID uint64 `url:"node_id" json:"node_id" validate:"required"`
}

// GetSSHIdentity gets node ssh information
func (n Node) GetSSHIdentity(ctx context.Context, req GetSSHIdentityRequest) (*SSHIdentity, error) {
	if err := validators.ValidateRequest(req); err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/get_ssh_identity"

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

	info := SSHIdentity{}

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

	return &info, nil
}
