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>
    /// Tabella dei grezzi
    /// </summary>
    [Table("MachGroupList")]
    public class MachGroupModel
    {
        #region Public Properties

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

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

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

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

        /// <summary>
        /// Stato locked (quando aperto da un dispositivo in rete)
        /// </summary>
        [Column("Lock")]
        public bool Locked { get; set; } = false;

        /// <summary>
        /// Indice di revisione (per recupero rapido modifiche)
        /// </summary>
        [Column("LogRev")]
        public int LogRev { get; set; } = 0;

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

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

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

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

        [ForeignKey("ProdDbId")]
        public ProdModel Prod { get; set; }

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

        [Column("ProdIndex")]
        public int ProdIndex { get; set; } = 10000;

        /// <summary>
        /// MachGroup state
        /// </summary>
        [Column("State")]
        public Core.ItemState State { get; set; } = Core.ItemState.ND;

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

        [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 MachGroupModel item))
                return false;

            if (H != item.H)
                return false;
            if (L != item.L)
                return false;
            if (W != item.W)
                return false;
            if (MachGroupId != item.MachGroupId)
                return false;
            if (Material != item.Material)
                return false;
            if (Name != item.Name)
                return false;
            if (ProdDbId != item.ProdDbId)
                return false;
            return true;
        }

        #endregion Public Methods
    }
}