/*
 * Seagull: A SQLite helper library
 * Copyright (C) Seagull Developers
 *
 * Seagull is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed with
 * this source distribution
 *
 * 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.1 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/>.
 */

#if !defined(SEAGULL_GLOBAL_HEADER_INSIDE) && !defined(SEAGULL_COMPILATION)
# error "only <seagull.h> may be included directly"
#endif

#ifndef SEAGULL_TRANSACTION_H
#define SEAGULL_TRANSACTION_H

#include <glib.h>
#include <gio/gio.h>

#include "seagulltypes.h"
#include "seagullversion.h"

G_BEGIN_DECLS

#define SEAGULL_TRANSACTION_ERROR seagull_transaction_error_quark()

/**
 * SeagullTransactionError:
 * @SEAGULL_TRANSACTION_ERROR_BEGIN_FAILED: the transaction failed to start
 * @SEAGULL_TRANSACTION_ERROR_COMMIT_FAILED: the transaction failed to finish
 * @SEAGULL_TRANSACTION_ERROR_ROLLBACK_FAILED: the transaction failed to roll
 *  back.
 *
 * Error codes returned by the transaction functions.
 *
 * Since: 0.2
 */
typedef enum {
	SEAGULL_TRANSACTION_ERROR_BEGIN_FAILED SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2,
	SEAGULL_TRANSACTION_ERROR_COMMIT_FAILED SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2,
	SEAGULL_TRANSACTION_ERROR_ROLLBACK_FAILED SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2,
} SeagullTransactionError;

/**
 * seagull_transaction_error_quark:
 *
 * The error domain to identify errors with transactions.
 *
 * Returns: The error domain.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
GQuark seagull_transaction_error_quark(void);

/**
 * seagull_transaction_begin:
 * @db: the database instance
 * @error: (out) (nullable): a return address for a #GError
 *
 * Begins a transaction.
 *
 * Return: true on success; otherwise false with @error set.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
gboolean seagull_transaction_begin(SeagullSqlite3 *db, GError **error);

/**
 * seagull_transaction_commit:
 * @db: the database instance
 * @error: (out) (nullable): a return address for a #GError
 *
 * Commits a transaction.
 *
 * Return: true on success; otherwise false with @error set.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
gboolean seagull_transaction_commit(SeagullSqlite3 *db, GError **error);

/**
 * seagull_transaction_rollback:
 * @db: the database instance
 * @error: (out) (nullable): a return address for a #GError
 *
 * Rolls back a transaction.
 *
 * Return: true on success; otherwise false with @error set.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
gboolean seagull_transaction_rollback(SeagullSqlite3 *db, GError **error);

G_END_DECLS

#endif /* SEAGULL_TRANSACTION_H */
