using GreenTree.Strohrmann.ERP.Core.Domain.Business;
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 CraftModel
    {
        #region Properties

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

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

        /// <summary>
        /// Craft creation date
        /// </summary>
        [Display(Name = "Gestartet am")]
        public DateTime CreationDate { get; set; }

        /// <summary>
        /// Craft customer
        /// </summary>
        [Display(Name = "Kunde")]
        public CustomerModel Customer { get; set; }

        /// <summary>
        /// Craft customer id
        /// </summary>
        public int CustomerId { get; set; }

        /// <summary>
        /// Craft employees
        /// </summary>
        [Display(Name = "Stunden")]
        public List<CraftEmployeeModel> CraftEmployees { get; set; }

        /// <summary>
        /// Craft materials
        /// </summary>
        [Display(Name = "Material")]
        public List<CraftMaterialModel> CraftMaterials { get; set; }

        #endregion

        #region Ctor

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

        /// <summary>
        /// Initializes a new instance of the CraftModel class
        /// </summary>
        /// <param name="craft">The base craft.</param>
        public CraftModel(Craft craft)
        {
            if (craft == null) return;

            Id = craft.Id;
            Name = craft.Name;
            CreationDate = craft.CreationDate;
            Customer = new CustomerModel(craft.Customer);
            CustomerId = craft.Customer.Id;
            CraftEmployees = craft.CraftEmployees
                .Select(ce => new CraftEmployeeModel(ce))
                .ToList();
            CraftMaterials = craft.CraftMaterials
                .Select(cm => new CraftMaterialModel(cm))
                .ToList();
        }

        #endregion
    }
}
