/* attachment_types.c generated by valac 0.56.19, the Vala compiler
 * generated from attachment_types.vala, do not modify */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_ATTACHMENT_TYPES (dc_attachment_types_get_type ())
#define DC_ATTACHMENT_TYPES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_ATTACHMENT_TYPES, DcAttachmentTypes))
#define DC_ATTACHMENT_TYPES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_ATTACHMENT_TYPES, DcAttachmentTypesClass))
#define DC_IS_ATTACHMENT_TYPES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_ATTACHMENT_TYPES))
#define DC_IS_ATTACHMENT_TYPES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_ATTACHMENT_TYPES))
#define DC_ATTACHMENT_TYPES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_ATTACHMENT_TYPES, DcAttachmentTypesClass))

typedef struct _DcAttachmentTypes DcAttachmentTypes;
typedef struct _DcAttachmentTypesClass DcAttachmentTypesClass;
typedef struct _DcAttachmentTypesPrivate DcAttachmentTypesPrivate;
enum  {
	DC_ATTACHMENT_TYPES_0_PROPERTY,
	DC_ATTACHMENT_TYPES_NUM_PROPERTIES
};
static GParamSpec* dc_attachment_types_properties[DC_ATTACHMENT_TYPES_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _DcAttachmentTypes {
	GObject parent_instance;
	DcAttachmentTypesPrivate * priv;
};

struct _DcAttachmentTypesClass {
	GObjectClass parent_class;
};

static gpointer dc_attachment_types_parent_class = NULL;

VALA_EXTERN GType dc_attachment_types_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcAttachmentTypes, g_object_unref)
VALA_EXTERN gchar* dc_attachment_types_infer_outgoing_view_type (const gchar* file_path,
                                                     const gchar* file_name);
static gboolean dc_attachment_types_has_sticker_extension (const gchar* value);
static gboolean dc_attachment_types_has_xdc_extension (const gchar* value);
VALA_EXTERN DcAttachmentTypes* dc_attachment_types_new (void);
VALA_EXTERN DcAttachmentTypes* dc_attachment_types_construct (GType object_type);
static GType dc_attachment_types_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
         * Keep outgoing classification aligned with Message.is_sticker_file():
         * these formats are presented by Parla as stickers, so they must also
         * be announced as stickers to other Delta Chat clients.
         */
gchar*
dc_attachment_types_infer_outgoing_view_type (const gchar* file_path,
                                              const gchar* file_name)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gchar* result;
	if (dc_attachment_types_has_sticker_extension (file_path)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = dc_attachment_types_has_sticker_extension (file_name);
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("Sticker");
		result = _tmp1_;
		return result;
	}
	if (dc_attachment_types_has_xdc_extension (file_path)) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = dc_attachment_types_has_xdc_extension (file_name);
	}
	if (_tmp2_) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("Webxdc");
		result = _tmp3_;
		return result;
	}
	result = NULL;
	return result;
}

static gboolean
dc_attachment_types_has_xdc_extension (const gchar* value)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (value != NULL) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = g_utf8_strdown (value, (gssize) -1);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_str_has_suffix (_tmp2_, ".xdc");
		_g_free0 (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gboolean
dc_attachment_types_has_sticker_extension (const gchar* value)
{
	gchar* lower = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	gboolean result;
	if (value == NULL) {
		result = FALSE;
		return result;
	}
	_tmp0_ = g_utf8_strdown (value, (gssize) -1);
	lower = _tmp0_;
	_tmp3_ = lower;
	if (g_str_has_suffix (_tmp3_, ".gif")) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp4_;
		_tmp4_ = lower;
		_tmp2_ = g_str_has_suffix (_tmp4_, ".webp");
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp5_;
		_tmp5_ = lower;
		_tmp1_ = g_str_has_suffix (_tmp5_, ".webm");
	}
	result = _tmp1_;
	_g_free0 (lower);
	return result;
}

DcAttachmentTypes*
dc_attachment_types_construct (GType object_type)
{
	DcAttachmentTypes * self = NULL;
	self = (DcAttachmentTypes*) g_object_new (object_type, NULL);
	return self;
}

DcAttachmentTypes*
dc_attachment_types_new (void)
{
	return dc_attachment_types_construct (DC_TYPE_ATTACHMENT_TYPES);
}

static void
dc_attachment_types_class_init (DcAttachmentTypesClass * klass,
                                gpointer klass_data)
{
	dc_attachment_types_parent_class = g_type_class_peek_parent (klass);
}

static void
dc_attachment_types_instance_init (DcAttachmentTypes * self,
                                   gpointer klass)
{
}

/** Semantic Delta Chat view types for outgoing attachments. */
static GType
dc_attachment_types_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcAttachmentTypesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_attachment_types_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcAttachmentTypes), 0, (GInstanceInitFunc) dc_attachment_types_instance_init, NULL };
	GType dc_attachment_types_type_id;
	dc_attachment_types_type_id = g_type_register_static (G_TYPE_OBJECT, "DcAttachmentTypes", &g_define_type_info, 0);
	return dc_attachment_types_type_id;
}

GType
dc_attachment_types_get_type (void)
{
	static volatile gsize dc_attachment_types_type_id__once = 0;
	if (g_once_init_enter (&dc_attachment_types_type_id__once)) {
		GType dc_attachment_types_type_id;
		dc_attachment_types_type_id = dc_attachment_types_get_type_once ();
		g_once_init_leave (&dc_attachment_types_type_id__once, dc_attachment_types_type_id);
	}
	return dc_attachment_types_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

