using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace Elwig.Models {
    [Table("contract"), PrimaryKey("VNr")]
    public class Contract {
        [Column("vnr")]
        public int VNr { get; set; }

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

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

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

        [ForeignKey("MgNr")]
        public virtual Member Member { get; private set; }

        [InverseProperty("Contract")]
        public virtual ISet<AreaCommitment> AreaCommitments { get; private set; }

        [NotMapped]
        public int Area => AreaCommitments.Select(a => a.Area).Sum();
    }
}