using Bogus;
using Microsoft.EntityFrameworkCore;
using TF6760ApiTest.Models;

namespace TF6760ApiTest.Data
{
    public class DataContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlite("Data Source=products.db");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var productFaker = new Faker<Product>()
               .RuleFor(p => p.Id, f => f.IndexFaker + 1)
               .RuleFor(p => p.CreatDateTime, f => f.Date.Past())
               .RuleFor(p => p.BarCode, f => f.Commerce.Ean13())
               .RuleFor(p => p.FinalPressure, f => f.Random.Float(0, 100))
               .RuleFor(p => p.FinalDisplacement, f => f.Random.Float(0, 50))
               .RuleFor(p => p.IsQualified, f => f.Random.Bool());

            var products = productFaker.Generate(100);

            modelBuilder.Entity<Product>().HasData(products);
        }
        public DbSet<Product> Products { get; set; }
    }
}
