using GreenTree.Strohrmann.ERP.Core.Domain.Business;
using GreenTree.Strohrmann.ERP.Core.Domain.Shared;
using GreenTree.Strohrmann.ERP.Domain.Model.Shared;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace GreenTree.Strohrmann.ERP.Domain.Model.Business
{
    public class CustomerMapping : TrackedEntityMapping<Customer>
    {
        public override void Configure(EntityTypeBuilder<Customer> builder)
        {
            base.Configure(builder);

            builder.ToTable("Customers");

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

            builder.Property(u => u.Id)
                .ValueGeneratedOnAdd();

            builder.HasOne(u => u.Title)
                .WithMany(d => d.Customers)
                .IsRequired()
                .OnDelete(DeleteBehavior.Restrict);

            builder.Property(u => u.Firstname)
                .IsRequired();

            builder.Property(u => u.Lastname)
                .IsRequired();

            builder.Property(u => u.CompanyName)
                .IsRequired(false);

            builder.Property(u => u.IsBusiness)
                .HasDefaultValue(false)
                .IsRequired();

            builder.Property(u => u.Address)
                .IsRequired();

            builder.Property(u => u.Town)
                .IsRequired();

            builder.Property(u => u.ZipCode)
                .IsRequired();

            builder.Property(u => u.Country)
                .IsRequired();

            builder.HasOne(u => u.Tax)
                .WithMany(d => d.Customers)
                .IsRequired(false)
                .OnDelete(DeleteBehavior.Restrict);
        }
    }
}
