using System.Collections.Generic;
using System.Linq;

using BS.Shared.DataContracts;
using System;

namespace BeWo.ViewModel.ListViewModel
{
    public class AssessmentSheetEntryListVM : AbstractDCListMapperVM<AssessmentSheetEntryDC, AssessmentSheetEntryVM>
    {
        //public AssessmentSheetEntryListVM(List<AssessmentSheetEntryDC> pDCs, List<AssessmentSheetCategoryDC> assessmentSheetCategories, List<ServiceRecordDC> serviceRecordsInMonth) : base(pDCs)
        public AssessmentSheetEntryListVM(List<AssessmentSheetEntryDC> pDCs, List<AssessmentSheetCategoryDC> assessmentSheetCategories, DateTime startDate)
            : base(pDCs)
        {
            //this.ServiceRecordsInMonth = serviceRecordsInMonth.Select(i => new ServiceRecordVM(i, null, null, null)).ToList();
            StartDate = startDate;
            this.AssessmentSheetCategories = assessmentSheetCategories;

            if (this.AssessmentSheetCategories != null)
            {
                this.AssessmentSheetCategories.Sort((c1, c2) =>
                {
	                var c = c1.Position.CompareTo(c2.Position);

	                if (c == 0 && c1.Description != null)
		                c = c1.Description.CompareTo(c2.Description);
	                return c;
                });
            }
        }

        public DateTime StartDate { get; set; }

        public List<AssessmentSheetCategoryDC> AssessmentSheetCategories { get; set; }

        public List<ServiceRecordVM> ServiceRecords { get; set; }

        public List<ServiceRecordVM> GetServiceRecordsForDate(DateTime date)
        {
            if (ServiceRecords != null)
                return ServiceRecords.Where(i => i.Date.Value.Date.Equals(date)).ToList();
            return new List<ServiceRecordVM>();
        }
    }
}