using Domain;
using Domain.Weapons;
using Domain.XML_Model;
using Microsoft.EntityFrameworkCore;

namespace DataLayer;

public class DeathwatchDbContext : DbContext
{
    public DbSet<Player> Players { get; set; }
    public DbSet<Weapon> Weapons { get; set; }
    public DbSet<Extension> Extensions { get; set; }
    public DbSet<Accessoire> Accessoires { get; set; }
    public DbSet<Root> Roots { get; set; }
    public DbSet<Extension> Extension { get; set; }
    public DbSet<Competence> Competences { get; set; }
    public DbSet<Amélioration> Améliorations { get; set; }
    public DbSet<Archétype> Archétypes { get; set; }
    public DbSet<Arme> Armes { get; set; }
    public DbSet<Armure> Armures { get; set; }
    public DbSet<Assermentation> Assermentations { get; set; }
    public DbSet<Attribut> Attributs { get; set; }
    public DbSet<Carrière> Carrières { get; set; }
    public DbSet<Coordonnée> Coordonnées { get; set; }
    public DbSet<Cybernétique> Cybernétiques { get; set; }
    public DbSet<Discipline> Disciplines { get; set; }
    public DbSet<Divination> Divinations { get; set; }
    public DbSet<Equipement> Equipements { get; set; }
    public DbSet<Implant> Implants { get; set; }
    public DbSet<Monde> Mondes { get; set; }
    public DbSet<Mutation> Mutations { get; set; }
    public DbSet<Pouvoir> Pouvoirs { get; set; }
    public DbSet<Promote> Promotions { get; set; }
    public DbSet<Seuil> Seuils { get; set; }
    public DbSet<Sousmonde> Sousmondes { get; set; }
    public DbSet<Talent> Talents { get; set; }
    public DbSet<Trait> Traits { get; set; }
    public DbSet<Trouble> Troubles { get; set; }
    public DbSet<TypeMonde> TypeMondes { get; set; }
    public DbSet<TypeName> TypesNom { get; set; }
    //public DbSet<AccessoiresArmes> AllAccessoiresArmes { get; set; }
    //public DbSet<Améliorations> AllAméliorations { get; set; }
    //public DbSet<Archétypes> AllArchétypes { get; set; }
    //public DbSet<Armes> AllArmes { get; set; }
    //public DbSet<Armures> AllArmures { get; set; }
    //public DbSet<Assermentations> AllAssermentations { get; set; }
    //public DbSet<AttributsArmes> AllAttributsArmes { get; set; }
    //public DbSet<Carrières> AllCarrières { get; set; }
    //public DbSet<Competences> AllCompetences { get; set; }
    //public DbSet<Coordonnées> AllCoordonnées { get; set; }
    //public DbSet<Cybernétiques> AllCybernétiques { get; set; }
    //public DbSet<Disciplines> AllDisciplines { get; set; }
    //public DbSet<Divinations> AllDivinations { get; set; }
    //public DbSet<Equipements> AllEquipements { get; set; }
    //public DbSet<Implants> AllImplants { get; set; }
    //public DbSet<Mondes> AllMondes { get; set; }
    //public DbSet<Mutations> AllMutations { get; set; }
    //public DbSet<Pouvoirs> AllPouvoirs { get; set; }
    //public DbSet<Promotions> AllPromotions { get; set; }
    //public DbSet<SeuilsXp> AllSeuilsXp { get; set; }
    //public DbSet<Sousmondes> AllSousmondes { get; set; }
    //public DbSet<Talents> AllTalents { get; set; }
    //public DbSet<Traits> AllTraits { get; set; }
    //public DbSet<Troubles> AllTroubles { get; set; }
    //public DbSet<TypeMondes> AllTypeMondes { get; set; }
    //public DbSet<TypesNom> AllTypesNom { get; set; }


    public DeathwatchDbContext() : base()
    {
    }

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

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            //optionsBuilder.UseSqlServer("Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ReadersDB");
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Player and Weapon relationship
        modelBuilder.Entity<Player>()
            .HasMany(p => p.Weapons)
            .WithMany(w => w.Players)
            .UsingEntity(j => j.ToTable("PlayerWeapons"));

        //// Extension table configuration
        //modelBuilder.Entity<Extension>().ToTable("Extensions");

        //// Accessoire table configuration
        //modelBuilder.Entity<Accessoire>().ToTable("Accessoires");

        //// Amelioration table configuration
        //modelBuilder.Entity<Amelioration>().ToTable("Ameliorations");

        // Additional configurations for XML Model classes

        modelBuilder.Entity<Extension>().ToTable("Extensions");
        modelBuilder.Entity<Accessoire>().ToTable("Accessoires");
        modelBuilder.Entity<Amélioration>().ToTable("Améliorations");
        modelBuilder.Entity<Archétype>().ToTable("Archétypes");
        modelBuilder.Entity<Arme>().ToTable("Armes");
        modelBuilder.Entity<Armure>().ToTable("Armures");
        modelBuilder.Entity<Assermentation>().ToTable("Assermentations");
        modelBuilder.Entity<Attribut>().ToTable("Attributs");
        modelBuilder.Entity<Carrière>().ToTable("Carrières");
        modelBuilder.Entity<Competence>().ToTable("Competences");
        modelBuilder.Entity<Coordonnée>().ToTable("Coordonnées");
        modelBuilder.Entity<Cybernétique>().ToTable("Cybernétiques");
        modelBuilder.Entity<Discipline>().ToTable("Disciplines");
        modelBuilder.Entity<Divination>().ToTable("Divinations");
        modelBuilder.Entity<Equipement>().ToTable("Equipements");
        modelBuilder.Entity<Implant>().ToTable("Implants");
        modelBuilder.Entity<Monde>().ToTable("Mondes");
        modelBuilder.Entity<Mutation>().ToTable("Mutations");
        modelBuilder.Entity<Pouvoir>().ToTable("Pouvoirs");
        modelBuilder.Entity<Promote>().ToTable("Promotions");
        modelBuilder.Entity<Seuil>().ToTable("Seuils");
        modelBuilder.Entity<Sousmonde>().ToTable("Sousmondes");
        modelBuilder.Entity<Talent>().ToTable("Talents");
        modelBuilder.Entity<Trait>().ToTable("Traits");
        modelBuilder.Entity<Trouble>().ToTable("Troubles");
        modelBuilder.Entity<TypeMonde>().ToTable("TypeMondes");
        modelBuilder.Entity<TypeName>().ToTable("TypesNom");

        //modelBuilder.Entity<AccessoiresArmes>()
        //    .HasMany(a => a.Accessoire)
        //    .WithOne()
        //    .HasForeignKey(x => x.AccessoireId);

        //modelBuilder.Entity<Améliorations>()
        //    .HasMany(a => a.Amélioration)
        //    .WithOne()
        //    .HasForeignKey(x => x.AméliorationId);

        //modelBuilder.Entity<Archétypes>()
        //    .HasMany(a => a.Archétype)
        //    .WithOne()
        //    .HasForeignKey(x => x.ArchétypeId);

        //modelBuilder.Entity<Armes>()
        //    .HasMany(a => a.Arme)
        //    .WithOne()
        //    .HasForeignKey(x => x.ArmeId);

        //modelBuilder.Entity<Armures>()
        //    .HasMany(a => a.Armure)
        //    .WithOne()
        //    .HasForeignKey(x => x.ArmureId);

        //modelBuilder.Entity<Assermentations>()
        //    .HasMany(a => a.Assermentation)
        //    .WithOne()
        //    .HasForeignKey(x => x.AssermentationId);

        //modelBuilder.Entity<AttributsArmes>()
        //    .HasMany(a => a.Attribut)
        //    .WithOne()
        //    .HasForeignKey(x => x.AttributId);

        //modelBuilder.Entity<Carrières>()
        //    .HasMany(c => c.Carrière)
        //    .WithOne()
        //    .HasForeignKey(x => x.CarrièreId);

        //modelBuilder.Entity<Competences>()
        //    .HasMany(c => c.Competence)
        //    .WithOne()
        //    .HasForeignKey(x => x.CompetenceId);

        //modelBuilder.Entity<Coordonnées>()
        //    .HasMany(c => c.Coordonnée)
        //    .WithOne()
        //    .HasForeignKey(x => x.CoordonnéeId);

        //modelBuilder.Entity<Cybernétiques>()
        //    .HasMany(c => c.Cybernétique)
        //    .WithOne()
        //    .HasForeignKey(x => x.CybernétiqueId);

        //modelBuilder.Entity<Disciplines>()
        //    .HasMany(d => d.Discipline)
        //    .WithOne()
        //    .HasForeignKey(x => x.DisciplineId);

        //modelBuilder.Entity<Divinations>()
        //    .HasMany(d => d.Divination)
        //    .WithOne()
        //    .HasForeignKey(x => x.DivinationId);

        //modelBuilder.Entity<Equipements>()
        //    .HasMany(e => e.Equipement)
        //    .WithOne()
        //    .HasForeignKey(x => x.EquipementId);

        //modelBuilder.Entity<Implants>()
        //    .HasMany(i => i.Implant)
        //    .WithOne()
        //    .HasForeignKey(x => x.ImplantId);

        //modelBuilder.Entity<Mondes>()
        //    .HasMany(m => m.Monde)
        //    .WithOne()
        //    .HasForeignKey(x => x.MondeId);

        //modelBuilder.Entity<Mutations>()
        //    .HasMany(m => m.Mutation)
        //    .WithOne()
        //    .HasForeignKey(x => x.MutationId);

        //modelBuilder.Entity<Pouvoirs>()
        //    .HasMany(p => p.Pouvoir)
        //    .WithOne()
        //    .HasForeignKey(x => x.PouvoirId);

        //modelBuilder.Entity<Promotions>()
        //    .HasMany(p => p.Promotion)
        //    .WithOne()
        //    .HasForeignKey(x => x.PromotionId);

        //modelBuilder.Entity<SeuilsXp>()
        //    .HasMany(s => s.Seuil)
        //    .WithOne()
        //    .HasForeignKey(x => x.SeuilId);

        //modelBuilder.Entity<Sousmondes>()
        //    .HasMany(s => s.Sousmonde)
        //    .WithOne()
        //    .HasForeignKey(x => x.SousmondeId);

        //modelBuilder.Entity<Talents>()
        //    .HasMany(t => t.Talent)
        //    .WithOne()
        //    .HasForeignKey(x => x.TalentId);

        //modelBuilder.Entity<Traits>()
        //    .HasMany(t => t.Trait)
        //    .WithOne()
        //    .HasForeignKey(x => x.TraitId);

        //modelBuilder.Entity<Troubles>()
        //    .HasMany(t => t.Trouble)
        //    .WithOne()
        //    .HasForeignKey(x => x.TroubleId);

        //modelBuilder.Entity<TypeMondes>()
        //    .HasMany(t => t.TypeMonde)
        //    .WithOne()
        //    .HasForeignKey(x => x.TypeMondeId);

        //modelBuilder.Entity<TypesNom>()
        //    .HasMany(t => t.TypeNom)
        //    .WithOne()
        //    .HasForeignKey(x => x.TypeNomId);

    }
}