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

        /// <summary>
        /// Craft material model index
        /// </summary>
        public int? Index { get; set; }

        /// <summary>
        /// Craft material Dictionary identifier
        /// </summary>
        public string DictIdentifier { get; set; }

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

        /// <summary>
        /// Craft
        /// </summary>
        [Display(Name = "Gewerk")]
        public virtual CraftModel Craft { get; set; }

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

        /// <summary>
        /// Material
        /// </summary>
        [Display(Name = "Material")]
        public MaterialModel Material { get; set; }

        /// <summary>
        /// The amount of the material
        /// </summary>
        [Display(Name = "Menge")]
        public decimal Amount { get; set; }

        /// <summary>
        /// The material calculation factor
        /// </summary>
        [Display(Name = "Kalkulationsfaktor")]
        [DisplayFormat(DataFormatString = "{0:P0}")]
        public decimal CalculationFactor { get; set; }

        /// <summary>
        /// The value of the employee working hours
        /// </summary>
        [Display(Name = "Wert")]
        [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:C}")]
        public float Value { get; set; }

        #endregion

        #region Ctor

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

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

            CraftId = craftMaterial.CraftId;
            MaterialId = craftMaterial.MaterialId;
            Amount = craftMaterial.Amount;
            CalculationFactor = craftMaterial.CalculationFactor;
            Value = Convert.ToSingle(craftMaterial.Value);
        }

        #endregion
    }
}
