using GreenTree.Strohrmann.ERP.Core.Domain.Business;
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 MaterialMapping : TrackedEntityMapping<Material>
    {
        public override void Configure(EntityTypeBuilder<Material> builder)
        {
            base.Configure(builder);

            builder.ToTable("Materials");

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

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

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

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

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

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

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

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

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

            builder.HasOne(u => u.DefaultUnit)
                .WithMany(s => s.Materials)
                .IsRequired()
                .OnDelete(DeleteBehavior.Restrict);

            builder.Property(u => u.PackageSize)
                .IsRequired()
                .HasDefaultValue(1);

            builder.HasOne(u => u.Supplier)
                .WithMany(s => s.Materials)
                .IsRequired()
                .OnDelete(DeleteBehavior.Restrict);
        }
    }
}
