
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "eps_interworking_info_1.h"

OpenAPI_eps_interworking_info_1_t *OpenAPI_eps_interworking_info_1_create(
    OpenAPI_list_t* eps_iwk_pgws,
    char *registration_time
)
{
    OpenAPI_eps_interworking_info_1_t *eps_interworking_info_1_local_var = ogs_malloc(sizeof(OpenAPI_eps_interworking_info_1_t));
    ogs_assert(eps_interworking_info_1_local_var);

    eps_interworking_info_1_local_var->eps_iwk_pgws = eps_iwk_pgws;
    eps_interworking_info_1_local_var->registration_time = registration_time;

    return eps_interworking_info_1_local_var;
}

void OpenAPI_eps_interworking_info_1_free(OpenAPI_eps_interworking_info_1_t *eps_interworking_info_1)
{
    OpenAPI_lnode_t *node = NULL;

    if (NULL == eps_interworking_info_1) {
        return;
    }
    if (eps_interworking_info_1->eps_iwk_pgws) {
        OpenAPI_list_for_each(eps_interworking_info_1->eps_iwk_pgws, node) {
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
            ogs_free(localKeyValue->key);
            OpenAPI_eps_iwk_pgw_1_free(localKeyValue->value);
            OpenAPI_map_free(localKeyValue);
        }
        OpenAPI_list_free(eps_interworking_info_1->eps_iwk_pgws);
        eps_interworking_info_1->eps_iwk_pgws = NULL;
    }
    if (eps_interworking_info_1->registration_time) {
        ogs_free(eps_interworking_info_1->registration_time);
        eps_interworking_info_1->registration_time = NULL;
    }
    ogs_free(eps_interworking_info_1);
}

cJSON *OpenAPI_eps_interworking_info_1_convertToJSON(OpenAPI_eps_interworking_info_1_t *eps_interworking_info_1)
{
    cJSON *item = NULL;
    OpenAPI_lnode_t *node = NULL;

    if (eps_interworking_info_1 == NULL) {
        ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [EpsInterworkingInfo_1]");
        return NULL;
    }

    item = cJSON_CreateObject();
    if (eps_interworking_info_1->eps_iwk_pgws) {
    cJSON *eps_iwk_pgws = cJSON_AddObjectToObject(item, "epsIwkPgws");
    if (eps_iwk_pgws == NULL) {
        ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [eps_iwk_pgws]");
        goto end;
    }
    cJSON *localMapObject = eps_iwk_pgws;
    if (eps_interworking_info_1->eps_iwk_pgws) {
        OpenAPI_list_for_each(eps_interworking_info_1->eps_iwk_pgws, node) {
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
            if (localKeyValue == NULL) {
                ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [eps_iwk_pgws]");
                goto end;
            }
            if (localKeyValue->key == NULL) {
                ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [eps_iwk_pgws]");
                goto end;
            }
            cJSON *itemLocal = localKeyValue->value ?
                OpenAPI_eps_iwk_pgw_1_convertToJSON(localKeyValue->value) :
                cJSON_CreateNull();
            if (itemLocal == NULL) {
                ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [inner]");
                goto end;
            }
            cJSON_AddItemToObject(localMapObject, localKeyValue->key, itemLocal);
        }
    }
    }

    if (eps_interworking_info_1->registration_time) {
    if (cJSON_AddStringToObject(item, "registrationTime", eps_interworking_info_1->registration_time) == NULL) {
        ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed [registration_time]");
        goto end;
    }
    }

end:
    return item;
}

OpenAPI_eps_interworking_info_1_t *OpenAPI_eps_interworking_info_1_parseFromJSON(cJSON *eps_interworking_info_1JSON)
{
    OpenAPI_eps_interworking_info_1_t *eps_interworking_info_1_local_var = NULL;
    OpenAPI_lnode_t *node = NULL;
    cJSON *eps_iwk_pgws = NULL;
    OpenAPI_list_t *eps_iwk_pgwsList = NULL;
    cJSON *registration_time = NULL;
    eps_iwk_pgws = cJSON_GetObjectItemCaseSensitive(eps_interworking_info_1JSON, "epsIwkPgws");
    if (eps_iwk_pgws) {
        cJSON *eps_iwk_pgws_local_map = NULL;
        if (!cJSON_IsObject(eps_iwk_pgws) && !cJSON_IsNull(eps_iwk_pgws)) {
            ogs_error("OpenAPI_eps_interworking_info_1_parseFromJSON() failed [eps_iwk_pgws]");
            goto end;
        }
        if (cJSON_IsObject(eps_iwk_pgws)) {
            eps_iwk_pgwsList = OpenAPI_list_create();
            OpenAPI_map_t *localMapKeyPair = NULL;
            cJSON_ArrayForEach(eps_iwk_pgws_local_map, eps_iwk_pgws) {
                cJSON *localMapObject = eps_iwk_pgws_local_map;
                if (cJSON_IsObject(localMapObject)) {
                    localMapKeyPair = OpenAPI_map_create(
                        ogs_strdup(localMapObject->string), OpenAPI_eps_iwk_pgw_1_parseFromJSON(localMapObject));
                } else if (cJSON_IsNull(localMapObject)) {
                    localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string), NULL);
                } else {
                    ogs_error("OpenAPI_eps_interworking_info_1_parseFromJSON() failed [inner]");
                    goto end;
                }
                OpenAPI_list_add(eps_iwk_pgwsList, localMapKeyPair);
            }
        }
    }

    registration_time = cJSON_GetObjectItemCaseSensitive(eps_interworking_info_1JSON, "registrationTime");
    if (registration_time) {
    if (!cJSON_IsString(registration_time) && !cJSON_IsNull(registration_time)) {
        ogs_error("OpenAPI_eps_interworking_info_1_parseFromJSON() failed [registration_time]");
        goto end;
    }
    }

    eps_interworking_info_1_local_var = OpenAPI_eps_interworking_info_1_create (
        eps_iwk_pgws ? eps_iwk_pgwsList : NULL,
        registration_time && !cJSON_IsNull(registration_time) ? ogs_strdup(registration_time->valuestring) : NULL
    );

    return eps_interworking_info_1_local_var;
end:
    if (eps_iwk_pgwsList) {
        OpenAPI_list_for_each(eps_iwk_pgwsList, node) {
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
            ogs_free(localKeyValue->key);
            OpenAPI_eps_iwk_pgw_1_free(localKeyValue->value);
            OpenAPI_map_free(localKeyValue);
        }
        OpenAPI_list_free(eps_iwk_pgwsList);
        eps_iwk_pgwsList = NULL;
    }
    return NULL;
}

OpenAPI_eps_interworking_info_1_t *OpenAPI_eps_interworking_info_1_copy(OpenAPI_eps_interworking_info_1_t *dst, OpenAPI_eps_interworking_info_1_t *src)
{
    cJSON *item = NULL;
    char *content = NULL;

    ogs_assert(src);
    item = OpenAPI_eps_interworking_info_1_convertToJSON(src);
    if (!item) {
        ogs_error("OpenAPI_eps_interworking_info_1_convertToJSON() failed");
        return NULL;
    }

    content = cJSON_Print(item);
    cJSON_Delete(item);

    if (!content) {
        ogs_error("cJSON_Print() failed");
        return NULL;
    }

    item = cJSON_Parse(content);
    ogs_free(content);
    if (!item) {
        ogs_error("cJSON_Parse() failed");
        return NULL;
    }

    OpenAPI_eps_interworking_info_1_free(dst);
    dst = OpenAPI_eps_interworking_info_1_parseFromJSON(item);
    cJSON_Delete(item);

    return dst;
}

