using Database.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Pos;


namespace Database
{
    public class PosDbContext : DbContext
    {

        public DbSet<EmployeeEntity> Employee { get; set; }
        public DbSet<ProductGroupEntity> ProductGroups { get; set; }
        public DbSet<ProductEntity> Products { get; set; }
        public DbSet<SaleEntity> Sales { get; set; }
        public DbSet<SaleLineEntity> SalesLines { get; set; }
        public DbSet<PaymentEntity> Payment { get; set; }

        protected override void OnConfiguring(
           DbContextOptionsBuilder optionsBuilder)
        {
            LoadConfig l = new LoadConfig();
            IConfiguration config = l.ByEnvironment();
            string connectionString = config["MariaSqlServer"].ToString();
            optionsBuilder
                .UseMySql(connectionString,ServerVersion.AutoDetect(connectionString))
                .UseLoggerFactory(LoggerFactory.Create(b => b
                    .AddFilter(level => level >= LogLevel.Information)))
                .EnableSensitiveDataLogging()
                .EnableDetailedErrors();
            base.OnConfiguring(optionsBuilder);
        }
    }
}
