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

/*
 * Copyright © 2026 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include "planify.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 PLANIFY_CLI_TYPE_TASK_VALIDATOR (planify_cli_task_validator_get_type ())
#define PLANIFY_CLI_TASK_VALIDATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLANIFY_CLI_TYPE_TASK_VALIDATOR, PlanifyCLITaskValidator))
#define PLANIFY_CLI_TASK_VALIDATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLANIFY_CLI_TYPE_TASK_VALIDATOR, PlanifyCLITaskValidatorClass))
#define PLANIFY_CLI_IS_TASK_VALIDATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLANIFY_CLI_TYPE_TASK_VALIDATOR))
#define PLANIFY_CLI_IS_TASK_VALIDATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLANIFY_CLI_TYPE_TASK_VALIDATOR))
#define PLANIFY_CLI_TASK_VALIDATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLANIFY_CLI_TYPE_TASK_VALIDATOR, PlanifyCLITaskValidatorClass))

typedef struct _PlanifyCLITaskValidator PlanifyCLITaskValidator;
typedef struct _PlanifyCLITaskValidatorClass PlanifyCLITaskValidatorClass;
typedef struct _PlanifyCLITaskValidatorPrivate PlanifyCLITaskValidatorPrivate;
enum  {
	PLANIFY_CLI_TASK_VALIDATOR_0_PROPERTY,
	PLANIFY_CLI_TASK_VALIDATOR_NUM_PROPERTIES
};
static GParamSpec* planify_cli_task_validator_properties[PLANIFY_CLI_TASK_VALIDATOR_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _PlanifyCLITaskValidator {
	GObject parent_instance;
	PlanifyCLITaskValidatorPrivate * priv;
};

struct _PlanifyCLITaskValidatorClass {
	GObjectClass parent_class;
};

static gpointer planify_cli_task_validator_parent_class = NULL;

VALA_EXTERN GType planify_cli_task_validator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PlanifyCLITaskValidator, g_object_unref)
VALA_EXTERN gboolean planify_cli_task_validator_validate_content (const gchar* content,
                                                      gchar** error_message);
VALA_EXTERN gboolean planify_cli_task_validator_validate_priority (gint priority,
                                                       gchar** error_message);
VALA_EXTERN gboolean planify_cli_task_validator_validate_and_parse_date (const gchar* due_date,
                                                             GDateTime** datetime,
                                                             gchar** error_message);
VALA_EXTERN gboolean planify_cli_task_validator_validate_parent_id (const gchar* parent_id,
                                                        gchar** error_message);
VALA_EXTERN PlanifyCLITaskValidator* planify_cli_task_validator_new (void);
VALA_EXTERN PlanifyCLITaskValidator* planify_cli_task_validator_construct (GType object_type);
static GType planify_cli_task_validator_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

gboolean
planify_cli_task_validator_validate_content (const gchar* content,
                                             gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	if (content == NULL) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (content);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") == 0;
		_g_free0 (_tmp2_);
	}
	if (_tmp0_) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("Error: --content is required");
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp3_;
		result = FALSE;
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	result = TRUE;
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

gboolean
planify_cli_task_validator_validate_priority (gint priority,
                                              gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	if (priority < 1) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = priority > 4;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("Error: --priority must be between 1 and 4");
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp1_;
		result = FALSE;
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	result = TRUE;
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

gboolean
planify_cli_task_validator_validate_and_parse_date (const gchar* due_date,
                                                    GDateTime** datetime,
                                                    gchar** error_message)
{
	GDateTime* _vala_datetime = NULL;
	gchar* _vala_error_message = NULL;
	gboolean _tmp0_ = FALSE;
	gchar** parts = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_;
	gchar** _tmp6_;
	gchar** _tmp7_;
	gint _tmp7__length1;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	gint year = 0;
	gchar** _tmp10_;
	gint _tmp10__length1;
	const gchar* _tmp11_;
	gint month = 0;
	gchar** _tmp12_;
	gint _tmp12__length1;
	const gchar* _tmp13_;
	gint day = 0;
	gchar** _tmp14_;
	gint _tmp14__length1;
	const gchar* _tmp15_;
	gboolean _tmp16_ = FALSE;
	gboolean _tmp17_ = FALSE;
	gboolean _tmp18_ = FALSE;
	gboolean _tmp19_ = FALSE;
	gboolean _tmp20_ = FALSE;
	GDateTime* _tmp22_;
	gboolean result;
	_g_date_time_unref0 (_vala_datetime);
	_vala_datetime = NULL;
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	if (due_date == NULL) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (due_date);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") == 0;
		_g_free0 (_tmp2_);
	}
	if (_tmp0_) {
		result = TRUE;
		if (datetime) {
			*datetime = _vala_datetime;
		} else {
			_g_date_time_unref0 (_vala_datetime);
		}
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	_tmp3_ = string_strip (due_date);
	_tmp4_ = _tmp3_;
	_tmp6_ = _tmp5_ = g_strsplit (_tmp4_, "-", 0);
	_tmp7_ = _tmp6_;
	_tmp7__length1 = _vala_array_length (_tmp5_);
	_g_free0 (_tmp4_);
	parts = _tmp7_;
	parts_length1 = _tmp7__length1;
	_parts_size_ = parts_length1;
	_tmp8_ = parts;
	_tmp8__length1 = parts_length1;
	if (_tmp8__length1 != 3) {
		gchar* _tmp9_;
		_tmp9_ = g_strdup ("Error: Invalid date format. Use YYYY-MM-DD");
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp9_;
		result = FALSE;
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		if (datetime) {
			*datetime = _vala_datetime;
		} else {
			_g_date_time_unref0 (_vala_datetime);
		}
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	_tmp10_ = parts;
	_tmp10__length1 = parts_length1;
	_tmp11_ = _tmp10_[0];
	year = atoi (_tmp11_);
	_tmp12_ = parts;
	_tmp12__length1 = parts_length1;
	_tmp13_ = _tmp12_[1];
	month = atoi (_tmp13_);
	_tmp14_ = parts;
	_tmp14__length1 = parts_length1;
	_tmp15_ = _tmp14_[2];
	day = atoi (_tmp15_);
	if (year < 1900) {
		_tmp20_ = TRUE;
	} else {
		_tmp20_ = year > 3000;
	}
	if (_tmp20_) {
		_tmp19_ = TRUE;
	} else {
		_tmp19_ = month < 1;
	}
	if (_tmp19_) {
		_tmp18_ = TRUE;
	} else {
		_tmp18_ = month > 12;
	}
	if (_tmp18_) {
		_tmp17_ = TRUE;
	} else {
		_tmp17_ = day < 1;
	}
	if (_tmp17_) {
		_tmp16_ = TRUE;
	} else {
		_tmp16_ = day > 31;
	}
	if (_tmp16_) {
		gchar* _tmp21_;
		_tmp21_ = g_strdup ("Error: Invalid date values");
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp21_;
		result = FALSE;
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		if (datetime) {
			*datetime = _vala_datetime;
		} else {
			_g_date_time_unref0 (_vala_datetime);
		}
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	_tmp22_ = g_date_time_new_local (year, month, day, 0, 0, (gdouble) 0);
	_g_date_time_unref0 (_vala_datetime);
	_vala_datetime = _tmp22_;
	result = TRUE;
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	if (datetime) {
		*datetime = _vala_datetime;
	} else {
		_g_date_time_unref0 (_vala_datetime);
	}
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

gboolean
planify_cli_task_validator_validate_parent_id (const gchar* parent_id,
                                               gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	gboolean _tmp0_ = FALSE;
	ObjectsItem* parent_item = NULL;
	ServicesStore* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	ObjectsItem* _tmp6_;
	ObjectsItem* _tmp7_;
	ObjectsItem* _tmp8_;
	gboolean result;
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	if (parent_id == NULL) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (parent_id);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") == 0;
		_g_free0 (_tmp2_);
	}
	if (_tmp0_) {
		result = TRUE;
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	_tmp3_ = services_store_instance ();
	_tmp4_ = string_strip (parent_id);
	_tmp5_ = _tmp4_;
	_tmp6_ = services_store_get_item (_tmp3_, _tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	parent_item = _tmp7_;
	_tmp8_ = parent_item;
	if (_tmp8_ == NULL) {
		gchar* _tmp9_;
		_tmp9_ = g_strdup_printf ("Error: Parent task ID '%s' not found", parent_id);
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp9_;
		result = FALSE;
		_g_object_unref0 (parent_item);
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	result = TRUE;
	_g_object_unref0 (parent_item);
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

PlanifyCLITaskValidator*
planify_cli_task_validator_construct (GType object_type)
{
	PlanifyCLITaskValidator * self = NULL;
	self = (PlanifyCLITaskValidator*) g_object_new (object_type, NULL);
	return self;
}

PlanifyCLITaskValidator*
planify_cli_task_validator_new (void)
{
	return planify_cli_task_validator_construct (PLANIFY_CLI_TYPE_TASK_VALIDATOR);
}

static void
planify_cli_task_validator_class_init (PlanifyCLITaskValidatorClass * klass,
                                       gpointer klass_data)
{
	planify_cli_task_validator_parent_class = g_type_class_peek_parent (klass);
}

static void
planify_cli_task_validator_instance_init (PlanifyCLITaskValidator * self,
                                          gpointer klass)
{
}

static GType
planify_cli_task_validator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PlanifyCLITaskValidatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) planify_cli_task_validator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlanifyCLITaskValidator), 0, (GInstanceInitFunc) planify_cli_task_validator_instance_init, NULL };
	GType planify_cli_task_validator_type_id;
	planify_cli_task_validator_type_id = g_type_register_static (G_TYPE_OBJECT, "PlanifyCLITaskValidator", &g_define_type_info, 0);
	return planify_cli_task_validator_type_id;
}

GType
planify_cli_task_validator_get_type (void)
{
	static volatile gsize planify_cli_task_validator_type_id__once = 0;
	if (g_once_init_enter (&planify_cli_task_validator_type_id__once)) {
		GType planify_cli_task_validator_type_id;
		planify_cli_task_validator_type_id = planify_cli_task_validator_get_type_once ();
		g_once_init_leave (&planify_cli_task_validator_type_id__once, planify_cli_task_validator_type_id);
	}
	return planify_cli_task_validator_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

