/*
 * Copyright (C) 2011-2023 Gary Kramlich <grim@reaperworld.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <gplugin.h>
#include <gplugin-native.h>

#include "introspectabletype.h"

enum {
	PROP_0,
	PROP_DUMMY,
	N_PROPERTIES,
};
static GParamSpec *properties[N_PROPERTIES] = {
	NULL,
};

struct _IntrospectableType {
	GObject gparent;

	gboolean dummy;
};

G_DEFINE_DYNAMIC_TYPE(IntrospectableType, introspectable_type, G_TYPE_OBJECT)

static void
introspectable_type_get_property(
	GObject *obj,
	guint param_id,
	GValue *value,
	GParamSpec *pspec)
{
	IntrospectableType *type = INTROSPECTABLE_TYPE(obj);

	switch(param_id) {
		case PROP_DUMMY:
			g_value_set_boolean(value, type->dummy);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
	}
}

static void
introspectable_type_set_property(
	GObject *obj,
	guint param_id,
	const GValue *value,
	GParamSpec *pspec)
{
	IntrospectableType *type = INTROSPECTABLE_TYPE(obj);

	switch(param_id) {
		case PROP_DUMMY:
			type->dummy = g_value_get_boolean(value);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
	}
}

static void
introspectable_type_init(G_GNUC_UNUSED IntrospectableType *inst)
{
}

static void
introspectable_type_class_finalize(G_GNUC_UNUSED IntrospectableTypeClass *klass)
{
}

static void
introspectable_type_class_init(IntrospectableTypeClass *klass)
{
	GObjectClass *obj_class = G_OBJECT_CLASS(klass);

	obj_class->get_property = introspectable_type_get_property;
	obj_class->set_property = introspectable_type_set_property;

	/**
	 * IntrospectableType:dummy:
	 *
	 * If it's a dummy or not.
	 */
	properties[PROP_DUMMY] = g_param_spec_boolean(
		"dummy",
		"dummy",
		"Whether or not this object is a dummy",
		FALSE,
		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

	g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
}

void
introspectable_type_register(GTypeModule *module)
{
	introspectable_type_register_type(module);
}
