//using FluentValidation; //using FluentValidation.Results; //using Raven.Client; //using Raven.Client.Documents; //using Raven.Client.Documents.Linq; //using Raven.Client.Documents.Session; //using System; //using System.Collections.Generic; //using System.Linq; //using System.Security.Claims; //using System.Threading.Tasks; //using zero.Core.Api; //using zero.Core.Attributes; //using zero.Core.Database; //using zero.Core.Entities; //using zero.Core.Extensions; //using zero.Core.Utils; //namespace zero.Core.Collections //{ // public abstract class CollectionPresetBase : ICollectionPresetBase, IDisposable where T : class, IPreset, new() // { // private IAsyncDocumentSession _session; // private string _database; // protected ICollectionInterceptorHandler InterceptorHandler { get; private set; } // protected virtual Action PreSave { get; set; } // public CollectionPresetBase(IZeroContext context, ICollectionInterceptorHandler interceptorHandler, IValidator validator = null) // { // Context = context; // Store = context.Store; // InterceptorHandler = interceptorHandler; // Validator = validator; // Database = Store.ResolvedDatabase; // } // /// // /// Zero context // /// // protected readonly IZeroContext Context; // /// // /// Document store // /// // protected readonly IZeroStore Store; // /// // /// The validator // /// // protected readonly IValidator Validator; // /// // /// Create an an async document session // /// // protected IAsyncDocumentSession Session // { // get // { // if (_session != null) // { // return _session; // } // _session = Store.OpenAsyncSession(Database ?? Store.ResolvedDatabase); // _session.Advanced.WaitForIndexesAfterSaveChanges(throwOnTimeout: false); // return _session; // } // } // /// // public string Database // { // get => _database; // set // { // if (value != _database) // { // _session?.Dispose(); // _session = null; // _database = value; // } // } // } // /// // public Guid Guid { get; private set; } = Guid.NewGuid(); // /// // public virtual void ApplyScope(string scope) // { // Database = scope is "shared" or "core" ? Context.Options.Raven.Database : Store.ResolvedDatabase; // } // /// // public virtual async Task Get(string key) // { // IPresetOverride preset = await Session.Query>().FirstOrDefaultAsync(x => x.Key == key); // return preset?.Model ?? new(); // } // /// // public virtual async Task> GetAll(string key) // { // List presets = await Session.Query().Where(x => x.Key == key).ToListAsync(); // //return preset ?? new(); // } // /// // public void Dispose() // { // Session?.Dispose(); // } // } // public interface IICollectionPredefinedBase : IDisposable where T : ZeroEntity // { // /// // /// Guid for this instance // /// // Guid Guid { get; } // /// // /// The database to operate on. // /// Is null by default, which uses the database from the resolved application. // /// // string Database { get; set; } // /// // /// Returns a new document queryable // /// // IRavenQueryable Query { get; } // /// // /// Applies the scope to the service instance // /// // void ApplyScope(string scope); // /// // /// Get an entity by Id // /// // Task GetById(string id); // /// // /// Get entities by ids // /// // Task> GetByIds(params string[] ids); // /// // /// Get entities by query // /// // Task> GetByQuery(ListQuery query); // /// // /// Get all entities from this collection. // /// Warning: Don't use this method for large collections. Stream the results instead. // /// // Task> GetAll(); // /// // /// Stream the collection // /// // IAsyncEnumerable Stream(); // /// // /// Stream the collection // /// // IAsyncEnumerable Stream(Func, IRavenQueryable> expression); // /// // /// Updates or creates an entity with an optional validator // /// // Task> Save(T model); // /// // /// Deletes an entity // /// // Task> Delete(T model); // /// // /// Deletes entities // /// // Task Delete(params T[] models); // /// // /// Deletes an entity by Id // /// // Task> DeleteById(string id); // /// // /// Deletes entities by Id // /// // Task DeleteByIds(params string[] ids); // /// // /// Delete a whole collection (with an optional query suffix, i.e. a where statement) // /// // Task> Purge(string querySuffix = null, Parameters parameters = null); // } // public interface ICollectionPresetBase : IDisposable where T : class, IPreset, new() // { // /// // /// Guid for this instance // /// // Guid Guid { get; } // /// // /// The database to operate on. // /// Is null by default, which uses the database from the resolved application. // /// // string Database { get; set; } // /// // /// Applies the scope to the service instance // /// // void ApplyScope(string scope); // /// // /// Get preset of a certain type // /// // Task Get(); // /// // /// Get all presets of a certain type // /// // Task> GetAll(); // } //}