using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EgtBEAMWALL.DataLayer.DatabaseModels
{
    /// <summary>
    /// Tabelal delle singole istsanze prodotte\
    /// </summary>
    [Table("PartList")]
    public class PartModel
    {
        #region Public Properties

        [ForeignKey("BTLPartDbId")]
        public BTLPartModel BTLPart { get; set; }

        [Column("BTLPartDbId")]
        public int? BTLPartDbId { get; set; }

        [Column("CalcState")]
        public int CALC_State { get; set; } = -1;

        /// <summary>
        /// Data End
        /// </summary>
        [Column("DtEnd")]
        public DateTime DtEnd { get; set; }

        /// <summary>
        /// Data Start
        /// </summary>
        [Column("DtStart")]
        public DateTime DtStart { get; set; }

        [Column("GRP")]
        public string GRP { get; set; } = "";

        [Column("H")]
        public double H { get; set; } = 0;

        [Column("L")]
        public double L { get; set; } = 0;

        [ForeignKey("MachGroupDbId")]
        public virtual MachGroupModel MachGroup { get; set; }

        [Column("MachGroupDbId")]
        public int? MachGroupDbId { get; set; }

        [Column("Material")]
        public string Material { get; set; } = "";

        [Column("NAM")]
        public string NAM { get; set; } = "";

        [Key, Column("DbId"), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int PartDbId { get; set; }

        [Column("Id")]
        public int PartId { get; set; }

        [Column("PDN")]
        public int PDN { get; set; } = 0;

        [Column("ROT")]
        public int ROT { get; set; } = 0;

        /// <summary>
        /// Stato della singola Part (da enum)
        /// </summary>
        [Column("State")]
        public Core.ItemState State { get; set; } = Core.ItemState.ND;

        [Column("W")]
        public double W { get; set; } = 0;

        #endregion Public Properties

        #region Public Methods

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Funzione di verifica equals limitata ai campi di pertinenza del ViewOptyimizer
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool ViewOptimEquals(object obj)
        {
            if (!(obj is PartModel item))
                return false;

            if (BTLPartDbId != item.BTLPartDbId)
                return false;
            if (H != item.H)
                return false;
            if (L != item.L)
                return false;
            if (W != item.W)
                return false;
            if (CALC_State != item.CALC_State)
                return false;
            if (Material != item.Material)
                return false;
            if (ROT != item.ROT)
                return false;
            if (PDN != item.PDN)
                return false;
            if (NAM != item.NAM)
                return false;

            return true;
        }

        #endregion Public Methods
    }
}