//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.Persistence;
using System.Collections;
using System.Threading;
///
/// The context for repository actions.
///
public interface IContext : IDisposable
{
///
/// Gets a value indicating whether this instance has changes.
///
bool HasChanges { get; }
///
/// Saves the changes of the context.
///
/// The cancellation token.
///
/// True, if the saving was successful; false, otherwise.
///
ValueTask SaveChangesAsync(CancellationToken cancellationToken = default);
///
/// Suspends the change notifications.
/// The notifications are re-enabled when the returned disposable is disposed,
/// but the notifications are not triggered for the changes which happened during the suspension.
///
/// A disposable, which must be disposed to re-enable notifications.
IDisposable SuspendChangeNotifications();
///
/// Detaches the specified item from the context, if required.
/// All reachable navigation properties are recursively detached from the context, too.
///
/// The item which should be detached.
/// true, if the object was persisted.
///
/// When calling this method, be sure to clear a back reference property before. Otherwise, you might detach more than you intended.
///
bool Detach(object item);
///
/// Attaches the specified item to the context in an unmodified state.
/// All reachable navigations are recursively attached to the context, too.
///
/// The item which should be attached.
///
/// When calling this method, be sure to clear a previous back reference property before. Otherwise, you might attach more than you intended.
///
void Attach(object item);
///
/// Creates a new instance of .
/// Attention: This operation needs a currently used context in the current thread!.
///
/// The type which should get created.
/// The arguments.
///
/// A new instance of .
///
T CreateNew(params object?[] args)
where T : class;
///
/// Creates a new instance of the given type.
/// Attention: This operation needs a currently used context in the current thread!.
///
/// The type which should get created.
/// The arguments.
///
/// A new instance of .
///
object CreateNew(Type type, params object?[] args);
///
/// Deletes the specified object.
///
/// The type of the object.
/// The object.
/// True, if successful; Otherwise, false.
ValueTask DeleteAsync(T obj)
where T : class;
///
/// Gets the object of the specified type by its identifier.
///
/// The type of the requested object.
/// The identifier.
/// The cancellation token.
///
/// The object of the specified type by its identifier.
///
Task GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
where T : class;
///
/// Gets the object of the specified type by its identifier.
///
/// The identifier.
/// The type of the requested object.
/// The cancellation token.
///
/// The object of the specified type by its identifier.
///
Task