namespace PARR.API.Contracts.V1.Responses.Statistics
{
    public class StatTemplateDistributorResponse
    {
        public required JobGroupWithDistributionConfigResponse JobGroup { get; set; }

        /// <summary>
        /// Всего шаблонов
        /// </summary>
        public int AllCount => ItemsList?.Sum(t => t.AllCount) ?? 0;

        /// <summary>
        /// Всего шаблонов с активированными шаблонами и расписаниями
        /// </summary>
        public int IsActivatedAllCount => ItemsList?.Sum(t => t.IsActivatedCount) ?? 0;

        /// <summary>
        /// Всего шаблонов с деактивированными шаблонами и/или расписаниями
        /// </summary>
        public int IsDeactivatedAllCount => ItemsList?.Sum(t => t.IsDeactivatedCount) ?? 0;

        /// <summary>
        /// Шаблонов назначенных на выходной день
        /// </summary>
        public int TemplatesInWeekendAllCount => ItemsList?.Sum(t => t.TemplatesInWeekendCount) ?? 0;

        public List<StatDistributorItemResponse>? ItemsList { get; set; }
    }

    public class StatDistributorItemResponse
    {
        /// <summary>
        /// Наименование поля по которому группируется
        /// </summary>
        public string? GroupFieldName { get; set; }

        public int AllCount => Statistics?.Sum(t => t.AllCount) ?? 0;
        public int IsActivatedCount => Statistics?.Sum(t => t.IsActivatedCount) ?? 0;
        public int IsDeactivatedCount => Statistics?.Sum(t => t.IsDeactivatedCount) ?? 0;
        public int TemplatesInWeekendCount => Statistics?.Sum(t => t.TemplatesInWeekendCount) ?? 0;

        public List<StatTemplateDistributorDateStat>? Statistics { get; set; }
    }

    public class StatTemplateDistributorDateStat
    {
        public DateTimeOffset Date { get; set; }
        public bool IsWorkDay { get; set; }
        public int AllCount { get; set; }
        public int IsActivatedCount { get; set; }
        public int IsDeactivatedCount { get; set; }
        public int TemplatesInWeekendCount => !IsWorkDay && Templates != null ? Templates.Count : 0;
        public List<StatTemplateDistribItem>? Templates { get; set; }
    }

    public class StatTemplateDistribItem
    {
        /// <summary>
        /// TemplateId
        /// </summary>
        public Guid Id { get; set; }    
        public required string Name { get; set; }
        public DateTimeOffset NextRun { get; set; }
        public bool IsActiveTemplate { get; set; }
        public bool IsActiveSchedular { get; set; }
        //public required ScheduleResponseAreaTimeOffsetResponse ResponseAreaOffset { get; set; }
    }
}
