/*
 * Go2Health.h
 * 
 * Gocator system communication library
 * Copyright (C) 2010 by LMI Technologies Inc.
 * 
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */
#include <z/zGo2Health.h>
#include <zIndicators.h>

GO2_EXPORT(Go2Status) Go2Health_Construct(Go2Health* health, zResult result)
{
    Go2Health output = zNIL; 
    Go2Status status = zOK; 

    zCHECK(zCalloc(&output, 1, sizeof(Go2HealthClass))); 

    if (!zSUCCESS(status = Go2Health_Init(output, result))) 
    {
        zCHECK(Go2Object_Destroy(output)); 
        return status; 
    }
    
    *health = output; 

    return zOK; 
}

GO2_EXPORT(Go2Status) Go2Health_Destroy(Go2Health health)
{
    return Go2Object_Destroy(health); 
}

GO2_EXPORT(Go2Status) Go2Health_Init(Go2Health health, zResult result)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);

    zCHECK(Go2Object_Init(health, GO2_TYPE_HEALTH)); 

    obj->Release = Go2Health_VRelease; 
    obj->result = result; 

    return zOK; 
}

GO2_EXPORT(Go2Status) Go2Health_VRelease(Go2Health health)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
  
    zCHECK(zResult_Destroy(obj->result)); 

    zCHECK(Go2Object_VRelease(health));  
        
    return zOK; 
}

GO2_EXPORT(Go2UInt32) Go2Health_Source(Go2Health health)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    return zIndicatorSet_Source(obj->result); 
}

GO2_EXPORT(Go2UInt32) Go2Health_Count(Go2Health health)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    return zIndicatorSet_Count(obj->result); 
}

GO2_EXPORT(Go2Int64) Go2Health_IdAt(Go2Health health, Go2UInt32 index)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    const zIndicator* indicator = zIndicatorSet_At(obj->result, index); 
    return zIS_NULL(indicator) ? 0 : indicator->id; 
}

GO2_EXPORT(Go2Int64) Go2Health_InstanceAt(Go2Health health, Go2UInt32 index)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    const zIndicator* indicator = zIndicatorSet_At(obj->result, index); 
    return zIS_NULL(indicator) ? 0 : indicator->instance; 
}

GO2_EXPORT(Go2Int64) Go2Health_ValueAt(Go2Health health, Go2UInt32 index)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    const zIndicator* indicator = zIndicatorSet_At(obj->result, index); 
    return zIS_NULL(indicator) ? 0 : indicator->value; 
}

GO2_EXPORT(zResult) Go2Health_Result(Go2Health health)
{
    Go2HealthClass* obj = zHANDLE_POINTER(health);
    return obj->result; 
}
