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

namespace Elwig.Models.Entities {
    [Table("payment_member"), PrimaryKey("Year", "AvNr", "MgNr")]
    public class PaymentMember {
        [Column("year")]
        public int Year { get; set; }

        [Column("avnr")]
        public int AvNr { get; set; }

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

        [Column("net_amount")]
        public long NetAmountValue { get; set; }
        [NotMapped]
        public decimal NetAmount {
            get => Variant.Season.DecFromDb(NetAmountValue);
            set => NetAmountValue = Variant.Season.DecToDb(value);
        }

        [Column("mod_abs")]
        public long ModAbsValue { get; set; }
        [NotMapped]
        public decimal ModAbs {
            get => Variant.Season.DecFromDb(ModAbsValue);
            set => ModAbsValue = Variant.Season.DecToDb(value);
        }

        [Column("mod_rel")]
        public double ModRelValue { get; set; }
        [NotMapped]
        public decimal ModRel {
            get => (decimal)ModRelValue;
            set => ModRelValue = (double)value;
        }

        [Column("amount")]
        public long AmountValue { get; private set; }
        [NotMapped]
        public decimal Amount => Variant.Season.DecFromDb(AmountValue);

        [ForeignKey("Year, AvNr")]
        public virtual PaymentVar Variant { get; private set; } = null!;

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

        [InverseProperty(nameof(Credit.Payment))]
        public virtual Credit? Credit { get; private set; }
    }
}
