#include <iostream>

#include "JSON.h"

/*
{
    "version":"1.0.0",
    "name":"testjson",
    "data":[
    {
        "id":"1",
        "first_name":"Steven",
        "last_name":"Thompson",
        "email":"sthompson0@spotify.com",
        "gender":"Male",
        "ip_address":"129.167.217.82"
    },
    {
        "id":"2",
        "first_name":"Doris",
        "last_name":"Daniels",
        "email":"ddaniels1@usgs.gov",
        "gender":"Female",
        "ip_address":"34.152.122.66"
    }
    ]

}
*/
/*
#define offsetof(s, m) (reinterpret_cast<size_t>(&reinterpret_cast<const volatile char&>(static_cast<s*>(nullptr)->m)))
#define offsetof(s,m)   (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m))
#define offsetof(st, m) ((size_t)&(((st *)0)->m))
*/
#define offsetof(s, m) (size_t)((char*)(&((s*)0)->m))


typedef struct {
	char		id[5];
	char		first_name[30];
	char		last_name[30];
	char		email[100];
	char		gender[10];
	char		ip_address[18];
} information;



JSON_ELEMENT  json_list[]= {
	/* 0 */ 	{NULL,		JSON_OBJ,		&json_list[1],											NULL},
	/* 1 */ 	{"version",		JSON_STR,		const_cast<void *>(reinterpret_cast<const void *>("1.0.0")),		&json_list[2]},
	/* 2 */ 	{"name",		JSON_STR,		const_cast<void *>(reinterpret_cast<const void *>("testjson")),		&json_list[3]},
	/* 3 */ 	{"data",		JSON_ARRAY,	&json_list[4],											NULL},
	/* 4 */ 	{NULL,		JSON_OBJ,		&json_list[5],											NULL},
	/* 5 */ 	{"id",			JSON_STR,		(void *)offsetof(information,	id),								&json_list[6]},
	/* 6 */ 	{"first_name",	JSON_STR,		(void *)offsetof(information,	first_name),						&json_list[7]},
	/* 7 */ 	{"last_name",	JSON_STR,		(void *)offsetof(information,	last_name),						&json_list[8]},
	/* 8 */ 	{"email",		JSON_STR,		(void *)offsetof(information,	email),							&json_list[9]},
	/* 9 */ 	{"gender",		JSON_STR,		(void *)offsetof(information,	gender),							&json_list[10]},
	/* 10 */ 	{"ip_address",	JSON_STR,		(void *)offsetof(information,	ip_address),						NULL}
};



int main(void)
{
	int  i=0;
	char * pBuff;
	JSON_ELEMENT *  json;
/*
	data_child_ip.child="34.152.122.66";
	data_child_gender.child="Male";
	data_child_email.child="ddaniels1@usgs.gov";
	data_child_lname.child="Thompson";
	data_child_fname.child="Steven";
	data_child_id.child="1";
	
	name.child="testjson";
	ver.child="1.0.0";
	pBuff=create_json(&entery);
	*/

	//const_cast<void *>(
	//reinterpret_cast<>
	
	json_list[10].child=const_cast<void *>(reinterpret_cast<const void *>("34.152.122.66"));
	json_list[9].child=const_cast<void *>(reinterpret_cast<const void *>("Male"));
	json_list[8].child=const_cast<void *>(reinterpret_cast<const void *>("ddaniels1@usgs.gov"));
	json_list[7].child=const_cast<void *>(reinterpret_cast<const void *>("Thompson"));
	json_list[6].child=const_cast<void *>(reinterpret_cast<const void *>("Steven"));
	json_list[5].child=const_cast<void *>(reinterpret_cast<const void *>("1"));
	json_list[2].child=const_cast<void *>(reinterpret_cast<const void *>("testjson"));
	json_list[1].child=const_cast<void *>(reinterpret_cast<const void *>("1.0.0"));

	pBuff=create_json(json_list);
	
	
	//printf("[%s]",pBuff);
	std::cout << "[" << pBuff << "]\n";
	
	json=get_json(pBuff);
	free_json(json);
	
	free(pBuff);
	
	
	return i;
}
