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

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

int main(int argc, char **argv) {
    const char *socket_name = "nsigner";
    const char *event_json = "{\"kind\":1,\"content\":\"hello from client example\",\"tags\":[],\"created_at\":1700000000}";
    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_sign_event(&client, "example-2", event_json, "main", &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;
}
