using PARR.Domain.Constants;
using PARR.Domain.Entities.Base;
using PARR.Domain.Entities.Job;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PARR.Domain.Entities
{
    /// <summary>
    /// Период автоматического распеделения РР
    /// </summary>
    [Table("DistributionPeriods", Schema = DatabaseSchemas.Schedule)]
    public class DistributionPeriod : IBaseEntity
    {
        [Key]
        public Guid Id { get; set; }

        [NotMapped]
        public DateTimeOffset DateCreated { get; set; }

        [NotMapped]
        public DateTimeOffset? DateModified { get; set; }

        public required string Name { get; set; }

        public required string Duration { get; set; }

        public required string Type { get; set; }

        //public DateTimeOffset AddDate
        //{
        //    get
        //    {
        //        var typeEnum = Enum.Parse(typeof(DistributionPeriodTypeEnum), Type);

        //        switch (typeEnum)
        //        {
        //            case (DistributionPeriodTypeEnum.Day):
        //                int.TryParse(Duration, out var intDays);
        //                return new DateTimeOffset().AddDays(intDays);

        //            case (DistributionPeriodTypeEnum.Month):
        //                int.TryParse(Duration, out var intMonth);
        //                return new DateTimeOffset().AddMonths(intMonth);

        //            case (DistributionPeriodTypeEnum.Year):
        //                int.TryParse(Duration, out var intYear);
        //                return new DateTimeOffset().AddYears(intYear);

        //            case (DistributionPeriodTypeEnum.TimeSpan):
        //                TimeSpan.TryParse(Duration, out var timeSpan);
        //                return new DateTimeOffset().Add(timeSpan);
        //        }

        //        return new DateTimeOffset();
        //    }
        //}

        [ForeignKey(nameof(Type))]
        public DistributionPeriodType? DistributionPeriodType { get; set; }

        public ICollection<JobGroupDistributionConfig> GroupDistributionConfig { get; set; } = new HashSet<JobGroupDistributionConfig>();

        //public ICollection<EsppSchTypeValue> EsppSchTypeValues { get; set; } = new HashSet<EsppSchTypeValue>();



    }
}
