using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using Domain.Models;

namespace Data.Mapping
{
    public class UserMap : IEntityTypeConfiguration<UserModel>
    {
        public void Configure(EntityTypeBuilder<UserModel> builder)
        {
            builder.ToTable("User");

            builder.HasKey(prop => prop.Id);

            builder.Property(prop => prop.Name)
                .HasConversion(prop => prop.ToString(), prop => prop)
                .IsRequired()
                .HasColumnName("Name")
                .HasColumnType("varchar(100)");

            builder.Property(prop => prop.Email)
               .HasConversion(prop => prop.ToString(), prop => prop)
               .IsRequired()
               .HasColumnName("Email")
               .HasColumnType("varchar(150)");

            builder.Property(prop => prop.CellPhone)
               .HasConversion(prop => prop.ToString(), prop => prop)
               .IsRequired()
               .HasColumnName("CellPhone")
               .HasColumnType("varchar(255)");

            builder.Property(prop => prop.Password)
                .HasConversion(prop => prop.ToString(), prop => prop)
                .IsRequired()
                .HasColumnName("Password")
                .HasColumnType("varchar(255)");

            builder.Property(prop => prop.Image)
               .HasConversion(prop => prop.ToString(), prop => prop)
               .HasDefaultValue(null)
               .HasColumnName("Image")
               .HasColumnType("varchar(255)");

            builder
            .HasIndex(u => u.Email)
            .IsUnique();

            builder
                .HasIndex(u => u.CellPhone)
                .IsUnique();

             
            builder
            .HasMany(u => u.Notification)
            .WithOne(n => n.User)
            .HasForeignKey(n => n.UserId);
           
            
        }
    }
}
