using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;

namespace Elwig.Models.Entities {
    [Table("member_history"), PrimaryKey("MgNr", "DateString", "Type")]
    public class MemberHistory {
        [Column("mgnr")]
        public int MgNr { get; set; }

        [Column("date")]
        public required string DateString { get; set; }
        [NotMapped]
        public DateOnly Date {
            get => DateOnly.ParseExact(DateString, "yyyy-MM-dd");
            set => value.ToString("yyyy-MM-dd");
        }

        [Column("type")]
        public required string Type { get; set; }

        [Column("business_shares")]
        public int BusinessShares { get; set; }

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

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