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

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

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

        [Column("name")]
        public required string Name { get; set; }

        [Column("date")]
        public required string DateString { get; set; }

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

        [Column("transfer_date")]
        public string? TransferDateString { get; set; }

        [NotMapped]
        public DateOnly? TransferDate {
            get => TransferDateString != null ? DateOnly.ParseExact(TransferDateString, "yyyy-MM-dd") : null;
            set => TransferDateString = value?.ToString("yyyy-MM-dd");
        }

        [Column("test_variant")]
        public bool TestVariant { get; set; }

        [Column("calc_time")]
        public int? CalcTime { get; set; }

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

        [Column("data")]
        public required string Data { get; set; }

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

        [InverseProperty("Variant")]
        public virtual ISet<PaymentMember> MemberPayments { get; private set; } = null!;

        [InverseProperty("Variant")]
        public virtual ISet<PaymentDeliveryPart> DeliveryPartPayments { get; private set; } = null!;

        [InverseProperty("Variant")]
        public virtual ISet<Credit> Credits { get; private set; } = null!;
    }
}
