using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GreenTree.Nachtragsmanagement.Data.Mapping.Deviation
{
    public class DeviationMap : EntityTypeConfiguration<Core.Domain.Deviation.Deviation>
    {
        public DeviationMap()
        {
            ToTable("Deviation");

            HasKey(d => d.Id);

            HasOptional(a => a.Site)
                .WithMany(s => s.Deviations)
                .HasForeignKey(a => a.SiteId);

            Property(d => d.Comment);
            Property(d => d.CustomNumber);
            Property(d => d.ReceiptDate);
            Property(d => d.AppendixDate);
            Property(d => d.Comment);
            Property(d => d.Value);
            Property(d => d.Percentage);

            HasOptional(d => d.Appendix)
                .WithMany(s => s.Deviations)
                .HasForeignKey(d => d.AppendixId);

            HasOptional(d => d.Status)
                .WithMany()
                .HasForeignKey(d => d.StatusId);

            HasOptional(d => d.Kind)
                .WithMany()
                .HasForeignKey(d => d.KindId);

            HasMany(s => s.DisturbanceValues)
                .WithMany()
                .Map(a => a.ToTable("DeviationDisturbanceValues"));
        }
    }
}
