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

namespace FSI.BT.IR.Plc.Settings.Log.Models
{
    public class Parameter
    {
        public Parameter()
        {
            Organizations = new HashSet<Organization>();
            Plcs = new HashSet<Plc>();
        }

        [Key]
        public int Id { get; set; }

        [DisplayName("Bezeichnung")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public string Name { get; set; }

        [DisplayName("Beschreibung")]
        public string? Description { get; set; }

        #region Organization
        
        [DisplayName("Organisation")]
        [Required(ErrorMessage = "Pflichtfeld")]
        [ForeignKey(nameof(Organization.Id))]
        public int OrganizationId { get; set; }

        public virtual Organization Organization { get; set; }

        public virtual ICollection<Organization> Organizations { get; set; }

        #endregion

        #region Plc

        [DisplayName("SPS")]
        [Required(ErrorMessage = "Pflichtfeld")]
        [ForeignKey(nameof(Plc.Id))]
        public int PlcId { get; set; }

        public virtual Plc Plc { get; set; }

        public virtual ICollection<Plc> Plcs { get; set; }

        #endregion

        [DisplayName("Datenbaustein-Nr.")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public int DbNo { get; set; }

        [DisplayName("Startadresse")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public int DbStart { get; set; }

        [DisplayName("Länge des Datentyps")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public int DbSize { get; set; }

        [DisplayName("Datentyp")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public DataType DataType { get; set; }

        [DisplayName("Standardwert")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public string DefaultValue { get; set; }

        [DisplayName("deaktiviert")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public bool Disabled { get; set; }

        [DisplayName("Erstellungsdatum")]
        public DateTime Created { get; set; } = DateTime.Now;

        [DisplayName("Bearbeitungsdatum")]
        public DateTime Updated { get; set; } = DateTime.Now;
    }
}
