using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace FSI.BT.IR.Plc.Settings.Log.Models
{

    public class Organization
    {
        public Organization()
        {
            Parents = new HashSet<Organization>();
        }

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

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

        [DisplayName("Kurzname")]
        [Required(ErrorMessage = "Pflichtfeld")]
        [StringLength(10)]
        public string ShortName { get; set; }

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

        [DisplayName("Übergeordnetes Objekt")]
        public int? ParentId { get; set; }
        
        [ForeignKey(nameof(Id))]
        public virtual Organization? Parent { get; set; }
        public virtual ICollection<Organization> Parents { get; set; }

        [DisplayName("Typ")]
        public OrganizationType Type { get; set; }

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

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

        [DisplayName("Bereich")]
        public string FullShortName { get; set; }

    }

    public enum OrganizationType
    {
        [Display(Name = "Firma")]
        company,
        [Display(Name = "Werk")]
        factory,
        [Display(Name = "Bereich")]
        area,
        [Display(Name = "Anlage")]
        plant,
        [Display(Name = "Teilanlage")]
        subPlant,
    }

}
