using Lookup.Database.Configurations;
using Lookup.Interface;
using Microsoft.EntityFrameworkCore;

namespace Lookup.Database;

/// <summary>
/// Basic <see cref="DbContext"/> 
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class LookupDbContext<TKey, TValue> : DbContext
  where TKey : class, IKeyEntity<TKey, TValue>
  where TValue : class, IRelated<TKey>, IValueEntity<TKey, TValue>
{
  /// <summary>
  /// Stored <see cref="IKeyEntity{TKey,TValue}"/> instances
  /// </summary>
  public virtual DbSet<IKeyEntity<TKey, TValue>> Keys { get; set; } = null!;

  /// <summary>
  /// Stored <see cref="IValueEntity{TKey,TValue}"/> instances
  /// </summary>
  public virtual DbSet<IValueEntity<TKey, TValue>> Values { get; set; } = null!;

  /// <inheritdoc />
  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
    modelBuilder.ApplyConfiguration(new LookupConfiguration<TKey, TValue>());
  }
}