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

            builder.ToTable("Employees");

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

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

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

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

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

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

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