using Electricity.Api.Entities;
using Microsoft.EntityFrameworkCore;

namespace Electricity.Api
{
    public partial class DatabaseContext : DbContext
    {
        public DatabaseContext()
        {
        }

        public DatabaseContext(DbContextOptions<DatabaseContext> options)
            : base(options)
        {
        }

        public virtual DbSet<ElectricityLog> ElectricityLogs { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlite("Data Source=test.db");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ElectricityLog>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("ElectricityLog");

                entity.HasIndex(e => e.Date, "idx_Date");

                entity.HasIndex(e => e.TimeUtc, "idx_TimeUtc");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
