using AutoMapper;
using PARR.API.Authentication.Models;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Statistics;
using PARR.API.MappingProfiles.Resolvers;
using PARR.Core.Repositories.Interfaces.Schedule;
using PARR.Domain.DTOs.Matching;
using PARR.Domain.DTOs.RobotTask;
using PARR.Domain.DTOs.Shortcode;
using PARR.Domain.DTOs.TaskDTO;
using PARR.Domain.DTOs.Workload;
using PARR.Domain.Entities;
using PARR.Domain.Entities.Base.History;
using PARR.Domain.Entities.Job;
using PARR.Domain.Entities.Schedule;
using PARR.Domain.Entities.Unit;

namespace PARR.API.MappingProfiles
{
    public class DomainToResponseProfile : Profile
    {
        public DomainToResponseProfile()
        {
            #region Template

            // --- Template ---
            CreateMap<Template, TemplateBaseResponse>()
                .Include<Template, TemplateResponse>()
                .Include<Template, TemplateListResponse>()
                .ForMember(d => d.Unit, o => o.MapFrom(s => s.Unit))
                .ForMember(d => d.StatusType, o => o.MapFrom(s => s.StatusType))
                .ForMember(d => d.Agent, o => o.MapFrom(s => s.Job!.Group!))
                .ForMember(d => d.SyncStatus, o => o.MapFrom(s => s.RobotConfigurations.OrderBy(t => t.RobotCode)))
                .ForMember(d => d.OrderCount, o => o.MapFrom(s => s.Orders.Count()))
                .ForMember(d => d.IsAutoDistributionEnabled, o => o.MapFrom(s => s.Job!.Group!.IsAutoDistributionEnabled))
                .ForMember(d => d.IsResponseAreaTimezone, o => o.MapFrom(s => s.Job!.Group!.IsResponseAreaTimezone));

            CreateMap<Template, TemplateListResponse>();

            CreateMap<Template, TemplateResponse>()
                .ForMember(d => d.Job, o => o.MapFrom(s => s.Job))
                //.ForMember(d => d.Unit, o => o.MapFrom(s => s.Unit))
                .ForMember(d => d.Process, o => o.MapFrom(s => s.Job!.Tnk!.Subprocess!.Process))
                .ForMember(d => d.Subprocess, o => o.MapFrom(s => s.Job!.Tnk!.Subprocess))
                .ForMember(d => d.Tnk, o => o.MapFrom(s => s.Job!.Tnk))
                .ForMember(d => d.ShortDescription, o => o.MapFrom(s => s.Job!.Group!.ShortDescription))
                .ForMember(d => d.FullDescription, o => o.MapFrom(s => s.Job!.Group!.FullDescription))
                .ForMember(d => d.Solution, o => o.MapFrom(s => s.Job!.Group!.Solution))
                .ForMember(d => d.TemplateDuration, o => o.MapFrom(s => s.Job!.Group!.TemplateDuration))
                .ForMember(d => d.Initiator, o => o.MapFrom<TemplateInitiatorResolver>())
                .ForMember(d => d.ClosingCode, o => o.MapFrom<TemplateClosingCodeResolver>())
                .ForMember(d => d.Category, o => o.MapFrom<TemplateCategoryResolver>())
                //.ForMember(d => d.SyncStatus, o => o.MapFrom(s => s.RobotConfigurations.OrderBy(t => t.RobotCode)))
                .ForMember(d => d.Schedule, o => o.MapFrom<TemplateScheduleResolver>())
                //.ForMember(d => d.Agent, o => o.MapFrom(s => s.Job!.Group!))
                //.ForMember(d => d.NextRun, o => o.MapFrom(s => s.NextRun))
                //.ForMember(d => d.LastRun, o => o.MapFrom(s => s.LastRun))
                //.ForMember(d => d.OrderCount, o => o.MapFrom(s => s.Orders.Count()))
                //.ForMember(d => d.IsAutoDistributionEnabled, o => o.MapFrom(s => s.Job!.Group!.IsAutoDistributionEnabled))
                //.ForMember(d => d.StatusType, o => o.MapFrom(s => s.StatusType))
                .ForMember(d => d.ScheduleExcludeType, o => o.MapFrom(s => s.Job!.Group!.ScheduleExcludeType))
                .ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.Job!.Group!.ScheduleExcludeTypeCalendar))
                .ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.Job.Group.DistributionConfig))
                ;
            // === Template ===


            CreateMap<Template, TemplateScheduleEsppIdResponse>();

            #endregion

            CreateMap<JobGroup, TemplateAgentResponse>()
                .ForMember(d => d.IsAgent, o => o.MapFrom(s => s.IsAgent))
                .ForMember(d => d.Name, o => o.MapFrom(s => s.AgentName))
                .ForMember(d => d.Script, o => o.MapFrom(s => s.AgentScript))
                .ForMember(d => d.TimeOutSec, o => o.MapFrom(s => s.AgentTimeOutSec));

            CreateMap<PARR.Domain.Entities.TaskStatus, TaskStatusResponse>();

            #region ScheduleResponseAreaTimeOffsetResponse

            CreateMap<ScheduleResponseAreaTimeOffset, ScheduleResponseAreaTimeOffsetResponse>();

            #endregion

            #region StatusTypeResponse

            CreateMap<TemplateStatusType, TemplateStatusTypeResponse>();

            #endregion

            #region Tnk

            CreateMap<Process, ProcessResponse>();

            CreateMap<Subprocess, SubprocessResponse>()
                .Include<Subprocess, SubprocessWithProcessResponse>();

            CreateMap<Subprocess, SubprocessWithProcessResponse>();


            CreateMap<Tnk, TnkResponse>()
                .Include<Tnk, TnkWithSubprocessResponse>();

            CreateMap<Tnk, TnkWithSubprocessResponse>();


            //CreateMap<Work, WorkResponse>()
            //    .Include<Work, WorkWithTnkResponse>();

            //CreateMap<Work, WorkWithTnkResponse>();

            #endregion

            #region Unit

            CreateMap<Unit, UnitBaseResponse>();

            CreateMap<UnitField, FieldResponse>()
                .ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.DisplayName)) ? s.AihitName : s.DisplayName));

            CreateMap<UnitFieldValue, UnitFieldValueResponse>();

            CreateMap<Unit, UnitResponse>()
                .Include<Unit, UnitWithAttributesResponse>()
                .Include<Unit, UnitRelationshipsAndAttributesResponse>()
                .ForMember(d => d.Name, o => o.MapFrom(s => s.Name));

            CreateMap<Unit, UnitWithAttributesResponse>()
                .Include<Unit, UnitRelationshipsAndAttributesResponse>()
                .ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues.GroupBy(g => g.Field)
                    .Select(fieldGroup => new AttributeResponse
                    {
                        Field = new FieldResponse
                        {
                            Id = fieldGroup.Key!.Id,
                            Name = string.IsNullOrEmpty(fieldGroup.Key.DisplayName) ? fieldGroup.Key.AihitName : fieldGroup.Key.DisplayName,
                            IsMultipleValue = fieldGroup.Key.IsMultipleValue,
                            Code = fieldGroup.Key.Code
                        },
                        Values = fieldGroup.Select(s => new UnitFieldValueResponse { Id = s.ValueId, Value = s.Value!.Value }).ToList()
                    }
                    ).OrderBy(o => o.Field.Name)
                ));


            CreateMap<Unit, UnitRelationshipsAndAttributesResponse>()
                .ForMember(d => d.Childrens, o => o.MapFrom(s => s.ChildUnits.Select(t => t.ChildUnit).OrderBy(t => t.Name)))
                .ForMember(d => d.Parents, o => o.MapFrom(s => s.ParentUnits.Select(t => t.ParentUnit).OrderBy(t => t.Name)));
            //.ForMember(d => d.Attributes, o => o.MapFrom(s => s.UnitValues.GroupBy(g => g.Field)
            //        .Select(fieldGroup => new AttributeResponse
            //        {
            //            Field = new FieldResponse
            //            {
            //                Id = fieldGroup.Key!.Id,
            //                Name = string.IsNullOrEmpty(fieldGroup.Key.DisplayName) ? fieldGroup.Key.AihitName : fieldGroup.Key.DisplayName,
            //                IsMultipleValue = fieldGroup.Key.IsMultipleValue
            //            },
            //            Values = fieldGroup.Select(s => new UnitFieldValueResponse { Id = s.ValueId, Value = s.Value!.Value }).ToList()
            //        }
            //    ).OrderBy(o => o.Field.Name)
            //));
            #endregion

            #region Robot

            CreateMap<RobotStatus, RobotStatusResponse>();

            CreateMap<RobotHistoryLevel, RobotHistoryLevelResponse>();

            CreateMap<RobotHistory, RobotHistoryResponse>()
                .ForMember(d => d.Level, o => o.MapFrom(s => s.RobotHistoryLevel))
                .ForMember(d => d.Date, o => o.MapFrom(s => s.DateCreated))
                .ForMember(d => d.TaskId, o => o.MapFrom(s => s.RobotConfigurationId))
                .ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.StatusTask))
                .ForMember(d => d.TemplateId, o => o.MapFrom(s => s.RobotConfiguration!.TemplateId))
                .ForMember(d => d.TemplateName, o => o.MapFrom(s => s.RobotConfiguration!.Template!.Name))
                .ForMember(d => d.Robot, o => o.MapFrom(s => s.RobotConfiguration!.Robot));

            #endregion

            #region RobotConfiguration
            // --- RobotConfiguration ---

            CreateMap<RobotTaskTemplate, RobotTaskTemplateResponse>();
            CreateMap<RobotTaskSchedule, RobotTaskScheduleResponse>();

            CreateMap<RobotTaskScheduleSch, RobotTaskScheduleSchResponse>();

            #region old robot task
            //CreateMap<RobotConfiguration, RobotTaskBaseResponse>()
            //    .Include<RobotConfiguration, RobotTaskTemplateResponse>()
            //    .Include<RobotConfiguration, RobotTaskScheduleResponse>()
            //    .ForMember(d => d.TaskId, o => o.MapFrom(s => s.Id));

            //CreateMap<RobotConfiguration, RobotTaskTemplateResponse>()
            //    .ForMember(d => d.IsActive, o => o.MapFrom(s => s.Template!.IsActiveTemplate))
            //    .ForMember(d => d.ClosingCode, o => o.MapFrom<RobotTaskTemplateClosingCodeResolver>())
            //    .ForMember(d => d.FullDescription, o => o.MapFrom(s => s.Template!.Job!.Group!.FullDescription))
            //    .ForMember(d => d.ShortDescription, o => o.MapFrom(s => s.Template!.Job!.Group!.ShortDescription))
            //    .ForMember(d => d.Solution, o => o.MapFrom(s => s.Template!.Job!.Group!.Solution))
            //    //.ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.Template!.Host!.ResponseArea!.Name))
            //    //ЗО берем у группы а не у хоста
            //    .ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.Template!.Unit!.BaseFields!.ResponseArea))
            //    .ForMember(d => d.TemplateDuration, o => o.MapFrom(s => s.Template!.Job!.Group!.TemplateDuration))
            //    .ForMember(d => d.Initiator, o => o.MapFrom<RobotTaskTemplateInitiatorResolver>())
            //    .ForMember(d => d.Category, o => o.MapFrom<RobotTaskTemplateCategoryResolver>())
            //    .ForMember(d => d.WorkGroup, o => o.MapFrom(s => s.Template!.Job!.WorkGroupMask))
            //    .ForMember(d => d.Ek, o => o.MapFrom(s => s.Template!.Unit!.Name))
            //    .ForMember(d => d.Name, o => o.MapFrom(s => s.Template!.Name))
            //    .ForMember(d => d.ProcessName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Process!.Name))
            //    .ForMember(d => d.ProcessEsppId, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Process!.EsppId))
            //    .ForMember(d => d.SubprocessName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Name))
            //    .ForMember(d => d.SubprocessEsppId, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.EsppId))
            //    .ForMember(d => d.TnkName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Name))
            //    .ForMember(d => d.TnkEsppId, o => o.MapFrom(s =>
            //                                                    s.Template!.Job!.Tnk!.EsppId.HasValue
            //                                                    ? s.Template!.Job!.Tnk!.EsppId.Value.ToString()
            //                                                    : string.Empty
            //                                                ))
            //    .ForMember(d => d.WorkName, o => o.MapFrom(s => s.Template!.Job!.WorkName))
            //    //.ForMember(d => d.WorkEsppId, o => o.MapFrom(s => s.Template!.Job!.EsppId))
            //    .ForMember(d => d.ScheduleEsppId, o => o.MapFrom(s => s.Template!.ScheduleEsppId));

            //CreateMap<RobotConfiguration, RobotTaskScheduleResponse>()
            //     .ForMember(d => d.EsppId, o => o.MapFrom(s => s.Template!.ScheduleEsppId))
            //     .ForMember(d => d.ScheduleName, o => o.MapFrom(s => s.Template!.Name))
            //     .ForMember(d => d.IsActive, o => o.MapFrom(s => s.Template!.IsActiveSchedule))
            //     .ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.Template!.Unit!.BaseFields!.ResponseArea))
            //     .ForMember(d => d.TemplateName, o => o.MapFrom(s => s.Template!.Name))
            //     .ForMember(d => d.TemplateId, o => o.MapFrom(s => s.Template!.Id))
            //     .ForMember(d => d.WorkGroup, o => o.MapFrom(s => s.Template!.Job!.WorkGroupMask))
            //     //.ForMember(d => d.Exclude, o => o.MapFrom<RobotTaskScheduleExcludeResolver>())
            //     .ForMember(d => d.Exclude, o => o.MapFrom(s => s.Template!.Job!.Group!.ScheduleExcludeType!.EsppName))
            //     //.ForMember(d => d.ExcludeCalendar, o => o.MapFrom<RobotTaskScheduleExcludeCalendarResolver>())
            //     .ForMember(d => d.ExcludeCalendar, o => o.MapFrom(s => s.Template!.Job!.Group!.ScheduleExcludeTypeCalendar != null ? s.Template!.Job!.Group!.ScheduleExcludeTypeCalendar.EsppName : null))
            //     //.ForMember(d => d.Timezone, o => o.MapFrom<RobotTaskScheduleTimezoneResolver>())
            //     .ForMember(d => d.RepeatRange, o => o.MapFrom<RobotTaskScheduleRepeatRangeResolver>())
            //     //todo: GenerationTime
            //     //.ForMember(d => d.GenerationTime, o => o.MapFrom(s => EsppScheduleHelpers.GetGenerationTime(s.Template!.NextRun)))
            //     //.ForMember(d => d.GenerationTime, o => o.MapFrom<RobotTaskScheduleGenerationTimeResolver>())
            //     //.ForMember(d => d.NextStart, o => o.MapFrom(s => EsppScheduleHelpers.GetNextRun(s.Template!.NextRun)))
            //     //.ForMember(d => d.NextStart, o => o.MapFrom<RobotTaskScheduleNextStartResolver>())
            //     .ForMember(d => d.ScheduleType, o => o.MapFrom(s =>
            //            s.Template!.Job!.Group!.EsppSchValues!.First()!.EsppSchTypeConfig!.EsppSchTypeSchedule!.Description))
            //     .ForMember(d => d.ScheduleTypeCode, o => o.MapFrom(s =>
            //            s.Template!.Job!.Group!.EsppSchValues!.First()!.EsppSchTypeConfig!.EsppSchTypeSchedule!.Id))
            //     .ForMember(d => d.Schedule, o => o.MapFrom<RobotTaskScheduleSchResolver>());

            #endregion

            CreateMap<Robot, RobotResponse>();

            CreateMap<PARR.Domain.Entities.TaskStatus, TaskStatusResponse>();

            CreateMap<RobotConfiguration, RobotConfigurationResponse>()
                .ForMember(d => d.Robot, o => o.MapFrom(s => s.Robot))
                .ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.TaskStatus))
                .ForMember(d => d.RobotStatus, o => o.MapFrom(s => s.RobotStatus));
            // === RobotConfiguration ===
            #endregion

            #region EsppSch
            CreateMap<EsppSchTypeSchedule, EsppScheduleTypeScheduleResponse>()
                .Include<EsppSchTypeSchedule, EsppScheduleTypeScheduleWithDataResponse>();

            CreateMap<EsppSchTypeSchedule, EsppScheduleTypeScheduleWithDataResponse>()
                .ForMember(d => d.Configs, o => o.MapFrom(s => s.EsppSchTypeConfigs.OrderBy(t => t.Order)));


            CreateMap<EsppSchTypeConfig, EsppScheduleTypeConfigWithDataResponse>()
                .ForMember(d => d.Type, o => o.MapFrom(s => s.EsppSchType));


            CreateMap<EsppSchType, EsppScheduleTypeResponse>()
                .Include<EsppSchType, EsppScheduleTypeWithDataResponse>();

            CreateMap<EsppSchType, EsppScheduleTypeWithDataResponse>()
                .ForMember(d => d.Values, o => o.MapFrom(s => s.EsppSchTypeValues.OrderBy(t => t.Order)));


            CreateMap<EsppSchTypeValue, EsppScheduleTypeValueResponse>();

            CreateMap<EsppScheduleValDto, EsppScheduleValResponse>()
                .ForMember(d => d.Order, o => o.MapFrom(s => s.Order))
                .ForMember(d => d.Value, o => o.MapFrom(s => s.Value))
                .ForMember(d => d.Type, o => o.MapFrom(s => s.Type));
            #endregion EsppSch 

            #region AgentHistory
            CreateMap<AgentHistoryLevel, AgentHistoryLevelResponse>();

            CreateMap<AgentHistory, AgentHistoryResponse>()
                .ForMember(d => d.Date, o => o.MapFrom(s => s.DateCreated))
                .ForMember(d => d.Level, o => o.MapFrom(s => s.AgentHistoryLevel))
                .ForMember(d => d.TemplateName, o => o.MapFrom(s => s.Template!.Name));

            #endregion

            #region User

            CreateMap<User, UserBaseResponse>()
                .Include<User, UserResponse>();

            CreateMap<User, UserBaseResponse>();

            CreateMap<User, UserResponse>()
                .ForMember(t => t.Roles, o => o.MapFrom(s => s.Roles.Select(t => t.Role).OrderBy(t => t!.Description)));

            CreateMap<Role, RoleResponse>();

            CreateMap<UserCache, UserProfileResponse>();

            #endregion

            #region Order

            CreateMap<OrderStatus, OrderStatusResponse>();

            CreateMap<Order, OrderResponseBase>()
                .Include<Order, OrderForAgentHistoryResponse>()
                .Include<Order, OrderResponse>();

            CreateMap<Order, OrderForAgentHistoryResponse>()
                .ForMember(s => s.Status, o => o.MapFrom(s => s.OrderStatus))
                .ForMember(s => s.NextStatus, o => o.MapFrom(s => s.NextStatus));

            CreateMap<Order, OrderResponse>()
                .ForMember(s => s.Status, o => o.MapFrom(s => s.OrderStatus))
                .ForMember(s => s.NextStatus, o => o.MapFrom(s => s.NextStatus));

            #endregion

            #region Job

            CreateMap<Job, JobBaseResponse>()
                .Include<Job, JobResponse>();

            CreateMap<Job, JobResponse>()
                .ForMember(d => d.AutoControl, o => o.MapFrom(s => s.AutoControl));

            CreateMap<JobUnitFilter, UnitFilterResponse>()
                .ForMember(d => d.UnitFilterMask, o => o.MapFrom(s => s.UnitFilter))
                .ForMember(d => d.FieldFilters, o => o.MapFrom(s => s.FieldFilters.OrderBy(o => o.UnitField!.AihitName)))
                .ForMember(d => d.RelationshipFilters, o => o.MapFrom(s => s.RelationshipFilters.OrderBy(o => o.UnitField!.AihitName)));

            CreateMap<JobFieldFilter, FieldResponse>();

            CreateMap<JobFieldFilter, FieldFilterResponse>()
                .ForMember(d => d.Field, o => o.MapFrom(s => s.UnitField));

            CreateMap<JobRelationshipFilter, RelationshipFilterResponse>()
                .ForMember(d => d.Field, o => o.MapFrom(s => s.UnitField));

            CreateMap<JobAutoControl, JobAutoControlResponse>();

            #endregion

            #region JobGroup

            CreateMap<JobGroup, JobGroupBaseResponse>()
                .Include<JobGroup, JobGroupResponse>()
                .Include<JobGroup, JobGroupWithDistributionConfigResponse>()
                .ForMember(d => d.GroupType, o => o.MapFrom(s => s.GroupType))
                .ForMember(d => d.GroupingUnitField, o => o.MapFrom(s => s.GroupingUnitField))
                .ForMember(d => d.IsWorkGroupTimezone, o => o.MapFrom(s => s.IsResponseAreaTimezone));

            CreateMap<JobGroup, JobGroupBaseResponse>()
               .ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName))
               .ForMember(d => d.IsWorkGroupTimezone, o => o.MapFrom(s => s.IsResponseAreaTimezone));

            CreateMap<JobGroup, JobGroupWithDistributionConfigResponse>()
                 .ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.DistributionConfig));

            CreateMap<JobGroup, JobGroupResponse>()
                .ForMember(d => d.ScheduleExcludeType, o => o.MapFrom(s => s.ScheduleExcludeType))
                .ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.ScheduleExcludeTypeCalendar));
            //.ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.DistributionConfig));


            #endregion

            #region JobGroupDistributionConfig

            CreateMap<JobGroupDistributionConfig, JobGroupDistributionConfigResponse>()
                .ForMember(d => d.Period, o => o.MapFrom(s => s.DistributionPeriod));

            CreateMap<DistributionPeriod, DistributionPeriodResponse>();

            #endregion

            #region ScheduleExcludeTypeCalendarResponse

            CreateMap<ScheduleExcludeTypeCalendar, ScheduleExcludeTypeCalendarResponse>();

            #endregion

            #region ScheduleExcludeTypeResponse

            CreateMap<ScheduleExcludeType, ScheduleExcludeTypeResponse>();

            #endregion

            #region JobGroupType

            CreateMap<JobGroupType, JobGroupTypeResponse>();

            #endregion

            CreateMap<WeekendDay, WeekendResponse>();

            #region TemplateHistory

            CreateMap<TemplateHistory, TemplateHistoryResponse>()
                .ForMember(d => d.TemplateId, o => o.MapFrom(s => s.ParentId))
                .ForMember(d => d.Initiator, o => o.MapFrom(s => s));

            #endregion


            #region Initiator

            CreateMap<IHistoryInitiator, HistoryInitiatorResponse>()
                .ForMember(d => d.Ip, o => o.MapFrom(s => s.InitiatorIp))
                .ForMember(d => d.Comment, o => o.MapFrom(s => s.InitiatorComment))
                .ForMember(d => d.ParrComponentId, o => o.MapFrom(s => s.InitiatorParrComponentId))
                .ForMember(d => d.ParrComponent, o => o.MapFrom<HistoryInitiatorParrComponentResolver>())
                .ForMember(d => d.User, o => o.MapFrom<HistoryInitiatorUserResolver>());

            #endregion

            CreateMap<ShortcodeInfoDto, ShortcodeResponse>();

            #region MatchingStatus -> MatchingStatusResponse

            CreateMap<MatchingStatus, MatchingStatusResponse>()
                .ForMember(d => d.DetailsJobGroups, o => o.MapFrom(s => s.DetailsJobGroups != null ? s.DetailsJobGroups.Select(t => t.Data) : null))
                .ForMember(d => d.DetailsJobs, o => o.MapFrom(s => s.DetailsJobs != null ? s.DetailsJobs.Select(t => t.Data) : null));

            #endregion


            #region StatWorkloadReportResponse

            CreateMap<WorkloadReport, StatWorkloadReportResponse>();

            CreateMap<WorkloadSummary, WorkloadSummaryResponse>();

            CreateMap<WorkloadSummaryItem, WorkloadSummaryItemResponse>();

            CreateMap<WorkloadDayItem, WorkloadDayItemResponse>();

            CreateMap<WorkloadStatisticItem, WorkloadStatisticItemResponse>();

            CreateMap<WorkloadDailyItem, WorkloadDailyItemResponse>();



            CreateMap<WorkloadCacheInfo, StatWorkloadCacheInfoResponse>();

            #endregion


            #region Task

            //CreateMap<TaskItemBase, TaskItemBaseResponse>()
            //    .Include<TaskItemBase, TaskItemResponse>()
            //    .Include<TaskItemBase, ActiveTaskResponse>();

            //CreateMap<TaskItemBase, TaskItemResponse>();

            CreateMap<ActiveTask, ActiveTaskResponse>();

            // ---

            CreateMap<TaskType, TaskItemTypeResponse>();

            CreateMap<PARR.Domain.DTOs.TaskDTO.TaskStatus, TaskItemStatusResponse>();

            #endregion

        }
    }


}
