using HanyadikHetVan.Data.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace HanyadikHetVan.Data
{
    public class ApplicationDbContext : IdentityDbContext<User, IdentityRole, string>
    {
        public DbSet<Pause> Pauses { get; set; }
        public DbSet<WeeklyTimeSpan> WeeklyTimeSpans { get; set; }

        public DbSet<FunFact> FunFacts { get; set; }

        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Pause>()
                .HasOne(s => s.WeeklyTimeSpan)
                .WithMany(s => s.Pauses)
                .OnDelete(DeleteBehavior.ClientCascade);

            modelBuilder.Entity<FunFact>()
                .HasOne(s => s.WeeklyTimeSpan)
                .WithMany(s => s.FunFacts)
                .OnDelete(DeleteBehavior.ClientCascade);

            modelBuilder.Entity<WeeklyTimeSpan>()
                .HasOne(s => s.User)
                .WithMany(s => s.WeeklyTimeSpans)
                .OnDelete(DeleteBehavior.ClientCascade);
        }
    }
}
