using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using WebApp.Entities;

namespace WebApp.Data
{
    public class ApplicationDbContext : IdentityDbContext//<User, IdentityRole<string>, string>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        public DbSet<User> WebUsers => Set<User>();
        public DbSet<Token> Tokens => Set<Token>();
        public DbSet<Organisation> Organisations => Set<Organisation>();
        public DbSet<Event> Events => Set<Event>();
        public DbSet<Skill> Skills => Set<Skill>();
        public DbSet<VolunteerSkill> VolunteerSkills => Set<VolunteerSkill>();
        public DbSet<EventSkill> EventSkills => Set<EventSkill>();
        public DbSet<EventRegistration> EventRegistrations => Set<EventRegistration>();
        public DbSet<Message> Messages => Set<Message>();
        public DbSet<MessageActivity> MessagesActivities => Set<MessageActivity>();

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            // Compose keys
            builder.Entity<VolunteerSkill>()
                .HasKey(vs => new { vs.UserId, vs.SkillId });

            builder.Entity<EventSkill>()
                .HasKey(es => new { es.EventId, es.SkillId });

            builder.Entity<EventRegistration>()
                .HasKey(er => new { er.UserId, er.EventId });

            builder.Entity<MessageActivity>()
                .HasKey(ma => new { ma.Sender, ma.Recipient });
        }
    }
}
