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.Appendix
{
    public class AppendixMap : EntityTypeConfiguration<Core.Domain.Appendix.Appendix>
    {
        public AppendixMap()
        {
            ToTable("Appendix");

            HasKey(a => a.Id);

            HasOptional(a => a.State)
                .WithMany()
                .HasForeignKey(a => a.StateId);

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

            Property(a => a.CustomNumber);
            Property(a => a.Description);
            Property(a => a.Comment);
            Property(a => a.Value);
            Property(a => a.Percentage);
            Property(a => a.OfferingNumber);
            Property(a => a.OfferingDate);
            Property(a => a.NegotiationDate);
            Property(a => a.NegotiationValue);
            Property(a => a.ProtocolExists);
            Property(a => a.OrderInvoiceCreated);
            Property(a => a.OrderNumber);
            Property(a => a.OrderDate);

            HasMany(s => s.CategoryValues)
                .WithMany()
                .Map(a => a.ToTable("AppendixCategoryValues"));

            HasMany(s => s.Deviations)
                .WithOptional();

            HasMany(s => s.Invoices)
                .WithOptional();
        }
    }
}
