// ========================================================
namespace Kerosene.ORM.Maps
{
using System;
using System.Collections.Generic;
// ====================================================
/// <summary>
/// Represents a column in the database that will be transfered back and forth the record associated with the
/// entities even if there is no matching member in the type for the column name. This class is typically used to
/// retrieve and persist the columns used by the extended members collection of the map.
/// </summary>
public interface IKMapForcedColumn
{
/// <summary>
/// The map this instance belongs to.
/// </summary>
IKMetaMap MetaMap { get; }
/// <summary>
/// The name of the forced column in the database.
/// </summary>
string Name { get; }
/// <summary>
/// If not null the delegate to invoke with (entity, value) arguments, typically to load into the entity the
/// value obtained from the record associated with this column. If this delegate is null, the value is loaded
/// into the record only if there is a matching member in the type, otherwise no transfer is performed.
/// </summary>
Action<object, object> LoadEntityDelegate { get; }
/// <summary>
/// Sets or clears the delegate to invoke with (entity, value) arguments, typically to load into the entity
/// the value obtained from the record associated with this column. If this delegate is null, the value is
/// loaded into the record only if there is a matching member in the type, otherwise no transfer is performed.
/// <para>This method fails if the map is already validated.</para>
/// <para>Returns this instance to permit a fluent syntax chaining.</para>
/// </summary>
/// <param name="onLoad">The delegate to set or null to clear it.</param>
IKMapForcedColumn OnLoadEntity(Action<object, object> onLoad);
/// <summary>
/// If not null the delegate to invoke with (entity) argument to obtain the value associated with this column
/// that will be written into the record. If this delegate is null then a value is obtained from the entity
/// only if there is a matching member in the type, otherwise no transfer is performed.
/// </summary>
Func<object, object> WriteRecordDelegate { get; }
/// <summary>
/// Sets or clears the delegate to invoke with (entity) argument to obtain the value associated with this
/// column that will be written into the record. If this delegate is null then a value is obtained from the
/// entity only if there is a matching member in the type, otherwise no transfer is performed.
/// <para>This method fails if the map is already validated.</para>
/// <para>Returns this instance to permit a fluent syntax chaining.</para>
/// </summary>
/// <param name="onWrite">The delegate to set or null to clear it.</param>
IKMapForcedColumn OnWriteRecord(Func<object, object> onWrite);
}
// ====================================================
/// <summary>
/// Represents the collection of columns in the database that will be transfered back and forth the record
/// associated with the entities even if there are no matching member in the type for the column names. This
/// class is typically used to retrieve and persist the columns used by the extended members collection of the
/// map.
/// </summary>
public interface IKMapForcedColumnCollection : IEnumerable<IKMapForcedColumn>
{
/// <summary>
/// The map this instance belongs to.
/// </summary>
IKMetaMap MetaMap { get; }
/// <summary>
/// Adds a new entry into this collection.
/// <para>Returns the new entry that has been created to permit a fluent syntax chaining.</para>
/// <para>This method fails if the map is already validated.</para>
/// </summary>
/// <param name="name">A dynamic lambda expression resolving into the name of the forced column.</param>
IKMapForcedColumn Add(Func<dynamic, object> name);
/// <summary>
/// Removes the given entry from this collection. Returns true if the entry has been removed sucessfully or
/// false otherwise.
/// </summary>
/// <param name="entry">The entry to remove from this collection.</param>
bool Remove(IKMapForcedColumn entry);
/// <summary>
/// Gets the number of entries in this collection.
/// </summary>
int Count { get; }
/// <summary>
/// Returns the first entry in this collection that matches the conditions given in the predicate, or null
/// if no such entry can be found.
/// </summary>
/// <param name="match">The predicate that defines the conditions of the entry to look for.</param>
IKMapForcedColumn Find(Predicate<IKMapForcedColumn> match);
}
}
// ========================================================