using GreenTree.Strohrmann.ERP.Core.Domain.Business;
using GreenTree.Strohrmann.ERP.Core.Domain.Shared;
using GreenTree.Strohrmann.ERP.Web.Models.Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace GreenTree.Strohrmann.ERP.Web.Models.Business
{
    public class EmployeeModel : TrackingModel
    {
        #region Properties

        /// <summary>
        /// Employee Id
        /// </summary>
        [Display(Name = "ID")]
        public int Id { get; set; }

        /// <summary>
        /// Employee first name
        /// </summary>
        [Display(Name = "Vorname")]
        public string Firstname { get; set; }

        /// <summary>
        /// Employee last name
        /// </summary>
        [Display(Name = "Nachname")]
        public string Lastname { get; set; }

        /// <summary>
        /// Employee mail address
        /// </summary>
        [Display(Name = "Mail-Adresse")]
        public string MailAddress { get; set; }

        /// <summary>
        /// Employee birthdate
        /// </summary>
        [Display(Name = "Geburtsdatum")]
        [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:dd.MM.yyyy}")]
        public DateTime Birthdate { get; set; }

        /// <summary>
        /// Employee degree
        /// </summary>
        [Display(Name = "Ausbildungsgrad")]
        public virtual EmployeeDegreeModel EmployeeDegree { get; set; }

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the EmployeeModel class
        /// </summary>
        public EmployeeModel() {  }

        /// <summary>
        /// Initializes a new instance of the EmployeeModel class
        /// </summary>
        /// <param name="employee">The base employee.</param>
        public EmployeeModel(Employee employee)
            : base(employee)
        {
            if (employee == null) return;

            Id = employee.Id;
            Firstname = employee.Firstname;
            Lastname = employee.Lastname;
            MailAddress = employee.MailAddress;
            Birthdate = employee.Birthdate.HasValue
                ? employee.Birthdate.Value
                : DateTime.MinValue;
            EmployeeDegree = new EmployeeDegreeModel(employee.EmployeeDegree);
        }

        #endregion
    }
}
