/*
 * SPDX-License-Identifier: 0BSD
 */

#ifndef NSIGNER_CLIENT_H
#define NSIGNER_CLIENT_H

#include <stddef.h>
#include <stdint.h>

#include <cJSON.h>

typedef struct {
    int fd;
    int timeout_ms;
    unsigned char auth_privkey[32];
    int auth_enabled;
    char auth_label[64];
    char last_error[128];
} nsigner_client_t;

void nsigner_client_init(nsigner_client_t *client);
void nsigner_client_close(nsigner_client_t *client);

int nsigner_client_connect_unix(nsigner_client_t *client,
                                const char *socket_name,
                                int timeout_ms);

int nsigner_client_set_auth(nsigner_client_t *client,
                            const unsigned char privkey[32],
                            const char *label);

const char *nsigner_client_last_error(const nsigner_client_t *client);

int nsigner_client_request_raw(nsigner_client_t *client,
                               const char *request_json,
                               char **out_response_json);

int nsigner_client_request(nsigner_client_t *client,
                           const char *id,
                           const char *method,
                           const cJSON *params,
                           char **out_response_json);

int nsigner_client_get_public_key(nsigner_client_t *client,
                                  const char *id,
                                  const char *selector,
                                  char **out_response_json);

int nsigner_client_sign_event(nsigner_client_t *client,
                              const char *id,
                              const char *event_json,
                              const char *role,
                              char **out_response_json);

#endif