#include <stdio.h>
#include <stdlib.h>

#include "../client/nsigner_client.h"

int main(int argc, char **argv) {
    const char *socket_name = "nsigner";
    nsigner_client_t client;
    char *response = NULL;

    if (argc > 1 && argv[1] != NULL && argv[1][0] != '\0') {
        socket_name = argv[1];
    }

    nsigner_client_init(&client);

    if (nsigner_client_connect_unix(&client, socket_name, 5000) != 0) {
        fprintf(stderr, "connect failed: %s\n", nsigner_client_last_error(&client));
        return 1;
    }

    if (nsigner_client_get_public_key(&client, "example-1", "", &response) != 0) {
        fprintf(stderr, "request failed: %s\n", nsigner_client_last_error(&client));
        nsigner_client_close(&client);
        return 1;
    }

    printf("%s\n", response);
    free(response);
    nsigner_client_close(&client);
    return 0;
}
