using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Elwig.Models.Entities {
    [Table("area_commitment"), PrimaryKey("FbNr")]
    public class AreaCom {
        [Column("fbnr")]
        public int FbNr { get; set; }

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

        [Column("vtrgid")]
        public required string VtrgId { get; set; }

        [Column("cultid")]
        public string? CultId { get; set; }

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

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

        [Column("gstnr")]
        public required string GstNr { get; set; }

        [Column("rdnr")]
        public int? RdNr { get; set; }

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

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

        [Column("comment")]
        public string? Comment { get; set; }

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

        [ForeignKey("VtrgId")]
        public virtual AreaComType AreaComType { get; private set; } = null!;

        [ForeignKey("CultId")]
        public virtual WineCult? WineCult { get; private set; }

        [ForeignKey("KgNr")]
        public virtual WbKg Kg { get; private set; } = null!;

        [ForeignKey("KgNr, RdNr")]
        public virtual WbRd? Rd { get; private set; }

        public int SearchScore(IEnumerable<string> keywords) {
            return Utils.GetSearchScore([
                 WineCult?.Name, Kg.AtKg.Name, Rd?.Name, GstNr, Comment,
            ], keywords);
        }
    }
}
