using FluentValidation; using Raven.Client.Documents.Session; using System.Collections.Generic; using zero.Core.Database; using zero.Core.Entities; using zero.Core.Extensions; namespace zero.Core.Collections { public abstract partial class CollectionInterceptor : ICollectionInterceptor where T : ZeroEntity { public class Parameters { /// /// The current zero context /// public IZeroContext Context { get; set; } /// /// Raven document store /// public IZeroStore Store { get; set; } /// /// Currently loaded document session /// public IAsyncDocumentSession Session { get; set; } /// /// Validator for the affected entity /// public IValidator Validator { get; set; } /// /// Parameters from the interceptor which ran on before the operation (only available for completed operations) /// public Dictionary Properties { get; set; } = new(); /// /// Get a typed property /// public TProp Property(string key) => Properties.GetValueOrDefault(key); /// /// Get a typed property /// public bool TryGetProperty(string key, out TProp property) => Properties.TryGetValue(key, out property); } public class ParametersWithModel : Parameters { /// /// The model which is affected /// public T Model { get; set; } } public class CreateParameters : ParametersWithModel { } public class UpdateParameters : ParametersWithModel { /// /// The Id of the model which is updated /// public string Id { get; set; } } public class SaveParameters : ParametersWithModel { /// /// The Id of the model which is saving (empty when creating) /// public string Id { get; set; } /// /// Whether this instruction is an update /// public bool IsUpdate { get; set; } /// /// Whether this instruction is create /// public bool IsCreate => !IsUpdate; } public class DeleteParameters : ParametersWithModel { /// /// The id of the model which is deleted /// public string Id { get; set; } } public class PurgeParameters : Parameters { } } }