using Lada.Framework.Data.Domains.Cms;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Cms
{
    public class UrlRecordMap : IEntityMappingConfiguration<UrlRecord>
    {
        public void Map(EntityTypeBuilder<UrlRecord> builder)
        {
            builder.HasKey(a => a.Id);
            builder.HasOne(e => e.Category).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.CategoryId).IsRequired(false);
            builder.HasOne(e => e.Tag).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.TagId).IsRequired(false);
            builder.HasOne(e => e.Post).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.PostId).IsRequired(false);
            builder.HasOne(e => e.Topic).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.TopicId).IsRequired(false);
            builder.HasOne(e => e.JobPost).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.JobPostId).IsRequired(false);
            builder.HasOne(e => e.Product).WithOne(u => u.UrlRecord).HasForeignKey<UrlRecord>(u => u.ProductId).IsRequired(false);
            //builder.HasOne(u => u.Category).WithOne(c => c.UrlRecord).HasForeignKey<Category>(c => c.UrlRecordId).IsRequired(false);
            builder.ToTable("UrlRecord");
        }
    }
}