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 CraftMapping : TrackedEntityMapping<Craft>
    {
        public override void Configure(EntityTypeBuilder<Craft> builder)
        {
            base.Configure(builder);

            builder.ToTable("Crafts");

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

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

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

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

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

            builder.HasOne(u => u.Customer)
                .WithMany(d => d.Crafts)
                .IsRequired()
                .OnDelete(DeleteBehavior.Restrict);
        }
    }
}
