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 Plc
    {
        public Plc()
        {
            Organizations = new HashSet<Organization>();
        }

        [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

        [DisplayName("IP-Adresse")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public string IpAdress { get; set; }

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

        [DisplayName("Slot")]
        [Required(ErrorMessage = "Pflichtfeld")]
        public int Slot { 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;

        [DisplayName("Name")]
        public string FullName
        {
            get
            {
                return Organization.FullShortName + " " + Name;
            }
        }
    }
}

