using Microsoft.EntityFrameworkCore;
using Aeldria.Api.Models;

namespace Aeldria.Api.Data;

public class AeldriaDbContext : DbContext
{
    public AeldriaDbContext(DbContextOptions<AeldriaDbContext> options)
        : base(options)
    {
    }

    public DbSet<Account> Accounts => Set<Account>();
    public DbSet<Character> Characters => Set<Character>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("aeldria");

        modelBuilder.Entity<Account>(entity =>
        {
            entity.ToTable("accounts");

            entity.HasKey(e => e.AccountId);

            entity.Property(e => e.AccountId)
                .HasColumnName("account_id");

            entity.Property(e => e.Username)
                .HasColumnName("username");

            entity.Property(e => e.Email)
                .HasColumnName("email");

            entity.Property(e => e.PasswordHash)
                .HasColumnName("password_hash");

            entity.Property(e => e.CreatedAt)
                .HasColumnName("created_at");

            entity.Property(e => e.LastLogin)
                .HasColumnName("last_login");

            entity.Property(e => e.IsBanned)
                .HasColumnName("is_banned");

            entity.Property(e => e.IsVerified)
                .HasColumnName("is_verified");
        });

        modelBuilder.Entity<Character>(entity =>
        {
            entity.ToTable("characters");

            entity.HasKey(e => e.CharacterId);

            entity.Property(e => e.CharacterId)
                .HasColumnName("character_id");

            entity.Property(e => e.AccountId)
                .HasColumnName("account_id");

            entity.Property(e => e.FactionId)
                .HasColumnName("faction_id");

            entity.Property(e => e.RaceId)
                .HasColumnName("race_id");

            entity.Property(e => e.Name)
                .HasColumnName("name");

            entity.Property(e => e.Level)
                .HasColumnName("level");

            entity.Property(e => e.Experience)
                .HasColumnName("experience");

            entity.Property(e => e.PosX)
                .HasColumnName("pos_x");

            entity.Property(e => e.PosY)
                .HasColumnName("pos_y");

            entity.Property(e => e.PosZ)
                .HasColumnName("pos_z");

            entity.Property(e => e.CreatedAt)
                .HasColumnName("created_at");
        });

        base.OnModelCreating(modelBuilder);
    }
}
