/*
 * This file is auto-generated, do not modify!
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include <glib.h>

#include "fu-intel-thunderbolt-struct.h"
#include "fu-byte-array.h"
#include "fu-bytes.h"
#include "fu-mem-private.h"
#include "fu-string.h"

#ifdef G_LOG_DOMAIN
  #undef G_LOG_DOMAIN
#endif
#define G_LOG_DOMAIN "FuStruct"

/**
 * fu_intel_thunderbolt_nvm_section_to_string:
 * @val: value, e.g. %FU_INTEL_THUNDERBOLT_NVM_SECTION_DROM
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_intel_thunderbolt_nvm_section_to_string(FuIntelThunderboltNvmSection val)
{
    if (val == FU_INTEL_THUNDERBOLT_NVM_SECTION_DIGITAL)
        return "digital";
    if (val == FU_INTEL_THUNDERBOLT_NVM_SECTION_DROM)
        return "drom";
    if (val == FU_INTEL_THUNDERBOLT_NVM_SECTION_ARC_PARAMS)
        return "arc-params";
    if (val == FU_INTEL_THUNDERBOLT_NVM_SECTION_DRAM_UCODE)
        return "dram-ucode";
    return NULL;
}


/**
 * fu_intel_thunderbolt_nvm_family_to_string:
 * @val: value, e.g. %FU_INTEL_THUNDERBOLT_NVM_FAMILY_FALCON_RIDGE
 *
 * Converts an enumerated value to a string.
 *
 * Returns: identifier string
 **/
const gchar *
fu_intel_thunderbolt_nvm_family_to_string(FuIntelThunderboltNvmFamily val)
{
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_FALCON_RIDGE)
        return "falcon-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_WIN_RIDGE)
        return "win-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_ALPINE_RIDGE)
        return "alpine-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_ALPINE_RIDGE_C)
        return "alpine-ridge-c";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_TITAN_RIDGE)
        return "titan-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_BB)
        return "bb";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_MAPLE_RIDGE)
        return "maple-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_GOSHEN_RIDGE)
        return "goshen-ridge";
    if (val == FU_INTEL_THUNDERBOLT_NVM_FAMILY_BARLOW_RIDGE)
        return "barlow-ridge";
    return NULL;
}
/**
 * fu_intel_thunderbolt_nvm_family_from_string:
 * @val: (nullable): a string, e.g. `falcon-ridge`
 *
 * Converts a string to an enumerated value.
 *
 * Returns: enumerated value
 **/
FuIntelThunderboltNvmFamily
fu_intel_thunderbolt_nvm_family_from_string(const gchar *val)
{
    if (g_strcmp0(val, "falcon-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_FALCON_RIDGE;
    if (g_strcmp0(val, "win-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_WIN_RIDGE;
    if (g_strcmp0(val, "alpine-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_ALPINE_RIDGE;
    if (g_strcmp0(val, "alpine-ridge-c") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_ALPINE_RIDGE_C;
    if (g_strcmp0(val, "titan-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_TITAN_RIDGE;
    if (g_strcmp0(val, "bb") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_BB;
    if (g_strcmp0(val, "maple-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_MAPLE_RIDGE;
    if (g_strcmp0(val, "goshen-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_GOSHEN_RIDGE;
    if (g_strcmp0(val, "barlow-ridge") == 0)
        return FU_INTEL_THUNDERBOLT_NVM_FAMILY_BARLOW_RIDGE;
    return FU_INTEL_THUNDERBOLT_NVM_FAMILY_UNKNOWN;
}
/**
 * fu_intel_thunderbolt_nvm_digital_ref: (skip):
 **/
FuIntelThunderboltNvmDigital *
fu_intel_thunderbolt_nvm_digital_ref(FuIntelThunderboltNvmDigital *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_digital_unref: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_unref(FuIntelThunderboltNvmDigital *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuIntelThunderboltNvmDigital refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_intel_thunderbolt_nvm_digital_new_internal: (skip):
 **/
static FuIntelThunderboltNvmDigital *
fu_intel_thunderbolt_nvm_digital_new_internal(void)
{
    FuIntelThunderboltNvmDigital *st = g_new0(FuIntelThunderboltNvmDigital, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_intel_thunderbolt_nvm_digital_set_available_sections: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_available_sections(FuIntelThunderboltNvmDigital *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[2] = value;
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_ucode: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_ucode(FuIntelThunderboltNvmDigital *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 3, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_device_id: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_device_id(FuIntelThunderboltNvmDigital *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 5, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_version: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_version(FuIntelThunderboltNvmDigital *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 9, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_flags_host: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_flags_host(FuIntelThunderboltNvmDigital *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[16] = value;
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_flash_size: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_flash_size(FuIntelThunderboltNvmDigital *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[69] = value;
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_arc_params: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_arc_params(FuIntelThunderboltNvmDigital *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 117, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_flags_is_native: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_flags_is_native(FuIntelThunderboltNvmDigital *st, guint8 value)
{
    g_return_if_fail(st != NULL);
    st->buf->data[123] = value;
}
/**
 * fu_intel_thunderbolt_nvm_digital_set_drom: (skip):
 **/
void
fu_intel_thunderbolt_nvm_digital_set_drom(FuIntelThunderboltNvmDigital *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 270, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_digital_new: (skip):
 **/
FuIntelThunderboltNvmDigital *
fu_intel_thunderbolt_nvm_digital_new(void)
{
    FuIntelThunderboltNvmDigital *st = fu_intel_thunderbolt_nvm_digital_new_internal();
    st->buf = g_byte_array_sized_new(288);
    fu_byte_array_set_size(st->buf, 288, 0x0);
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_drom_ref: (skip):
 **/
FuIntelThunderboltNvmDrom *
fu_intel_thunderbolt_nvm_drom_ref(FuIntelThunderboltNvmDrom *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_drom_unref: (skip):
 **/
void
fu_intel_thunderbolt_nvm_drom_unref(FuIntelThunderboltNvmDrom *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuIntelThunderboltNvmDrom refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_intel_thunderbolt_nvm_drom_new_internal: (skip):
 **/
static FuIntelThunderboltNvmDrom *
fu_intel_thunderbolt_nvm_drom_new_internal(void)
{
    FuIntelThunderboltNvmDrom *st = g_new0(FuIntelThunderboltNvmDrom, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_intel_thunderbolt_nvm_drom_set_vendor_id: (skip):
 **/
void
fu_intel_thunderbolt_nvm_drom_set_vendor_id(FuIntelThunderboltNvmDrom *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_drom_set_model_id: (skip):
 **/
void
fu_intel_thunderbolt_nvm_drom_set_model_id(FuIntelThunderboltNvmDrom *st, guint16 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint16(st->buf->data + 18, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_drom_new: (skip):
 **/
FuIntelThunderboltNvmDrom *
fu_intel_thunderbolt_nvm_drom_new(void)
{
    FuIntelThunderboltNvmDrom *st = fu_intel_thunderbolt_nvm_drom_new_internal();
    st->buf = g_byte_array_sized_new(32);
    fu_byte_array_set_size(st->buf, 32, 0x0);
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_arc_params_ref: (skip):
 **/
FuIntelThunderboltNvmArcParams *
fu_intel_thunderbolt_nvm_arc_params_ref(FuIntelThunderboltNvmArcParams *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_arc_params_unref: (skip):
 **/
void
fu_intel_thunderbolt_nvm_arc_params_unref(FuIntelThunderboltNvmArcParams *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuIntelThunderboltNvmArcParams refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_intel_thunderbolt_nvm_arc_params_new_internal: (skip):
 **/
static FuIntelThunderboltNvmArcParams *
fu_intel_thunderbolt_nvm_arc_params_new_internal(void)
{
    FuIntelThunderboltNvmArcParams *st = g_new0(FuIntelThunderboltNvmArcParams, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_intel_thunderbolt_nvm_arc_params_set_pd_pointer: (skip):
 **/
void
fu_intel_thunderbolt_nvm_arc_params_set_pd_pointer(FuIntelThunderboltNvmArcParams *st, guint32 value)
{
    g_return_if_fail(st != NULL);
    fu_memwrite_uint32(st->buf->data + 268, value, G_LITTLE_ENDIAN);
}
/**
 * fu_intel_thunderbolt_nvm_arc_params_new: (skip):
 **/
FuIntelThunderboltNvmArcParams *
fu_intel_thunderbolt_nvm_arc_params_new(void)
{
    FuIntelThunderboltNvmArcParams *st = fu_intel_thunderbolt_nvm_arc_params_new_internal();
    st->buf = g_byte_array_sized_new(288);
    fu_byte_array_set_size(st->buf, 288, 0x0);
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_dram_ref: (skip):
 **/
FuIntelThunderboltNvmDram *
fu_intel_thunderbolt_nvm_dram_ref(FuIntelThunderboltNvmDram *st)
{
    g_return_val_if_fail(st != NULL, NULL);
    st->refcount++;
    return st;
}
/**
 * fu_intel_thunderbolt_nvm_dram_unref: (skip):
 **/
void
fu_intel_thunderbolt_nvm_dram_unref(FuIntelThunderboltNvmDram *st)
{
    g_return_if_fail(st != NULL);
    if (st->refcount == 0) {
        g_critical("FuIntelThunderboltNvmDram refcount already zero");
        return;
    }
    if (--st->refcount > 0)
        return;
    if (st->buf != NULL)
        g_byte_array_unref(st->buf);
    g_free(st);
}
/**
 * fu_intel_thunderbolt_nvm_dram_new_internal: (skip):
 **/
static FuIntelThunderboltNvmDram *
fu_intel_thunderbolt_nvm_dram_new_internal(void)
{
    FuIntelThunderboltNvmDram *st = g_new0(FuIntelThunderboltNvmDram, 1);
    st->refcount = 1;
    return st;
}

/* getters */

/* setters */
/**
 * fu_intel_thunderbolt_nvm_dram_new: (skip):
 **/
FuIntelThunderboltNvmDram *
fu_intel_thunderbolt_nvm_dram_new(void)
{
    FuIntelThunderboltNvmDram *st = fu_intel_thunderbolt_nvm_dram_new_internal();
    st->buf = g_byte_array_sized_new(16);
    fu_byte_array_set_size(st->buf, 16, 0x0);
    return st;
}
