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

namespace GreenTree.Strohrmann.ERP.Domain.Model.Business
{
    public class CraftEmployeeMapping : IEntityTypeConfiguration<CraftEmployee>
    {
        public void Configure(EntityTypeBuilder<CraftEmployee> builder)
        {
            builder.ToTable("CraftEmployees");

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

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

            builder.Property(ce => ce.Amount)
                .IsRequired();

            builder.Property(ce => ce.Value)
                .IsRequired();

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

            builder.HasOne(rp => rp.Craft)
                .WithMany(r => r.CraftEmployees)
                .HasForeignKey(rp => rp.CraftId)
                .IsRequired();
        }
    }
}
