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 MaterialModel : TrackingModel
    {
        #region Properties

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

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

        /// <summary>
        /// Material item number
        /// </summary>
        [Display(Name = "Artikel- / Materialnummer d. Lieferanten")]
        public string ItemNumber { get; set; }

        /// <summary>
        /// Material description
        /// </summary>
        [Display(Name = "Beschreibung")]
        public string Description { get; set; }

        /// <summary>
        /// Material net value
        /// </summary>
        [Display(Name = "Nettowert")]
        [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:C}")]
        public float NetValue { get; set; }

        /// <summary>
        /// Material height
        /// </summary>
        [Display(Name = "Höhe")]
        public decimal Height { get; set; }

        /// <summary>
        /// Material width
        /// </summary>
        [Display(Name = "Breite")]
        public decimal Width { get; set; }

        /// <summary>
        /// Material depth
        /// </summary>
        [Display(Name = "Tiefe")]
        public decimal Depth { get; set; }

        /// <summary>
        /// Material dimensions (read only)
        /// </summary>
        [Display(Name = "Maße")]
        public string Dimension 
        {
            get
            {
                return String.Format("{0:F2}x{1:F2}x{2:F2}", Height, Width, Depth);
            }
        }

        /// <summary>
        /// Material default unit
        /// </summary>
        [Display(Name = "Einheit")]
        public UnitModel DefaultUnit { get; set; }

        /// <summary>
        /// The amount of items per package
        /// </summary>
        [Display(Name = "Packungsgröße / -menge")]
        public decimal PackageSize { get; set; }

        /// <summary>
        /// Material supplier
        /// </summary>
        [Display(Name = "Lieferant")]
        public SupplierModel Supplier { get; set; }

        #endregion

        #region Ctor

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

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

            Id = material.Id;
            Name = material.Name;
            ItemNumber = material.ItemNumber;
            Description = material.Description;
            NetValue = Convert.ToSingle(material.NetValue);
            Height = material.Height;
            Width = material.Width;
            Depth = material.Depth;
            DefaultUnit = new UnitModel(material.DefaultUnit);
            PackageSize = material.PackageSize;
            Supplier = new SupplierModel(material.Supplier);
        }

        #endregion
    }
}
