﻿using AlaCarte.Domain.Contract;
using AlaCarte.Domain.Model;
using System.Collections.Generic;
using System.Linq;

namespace AlaCarte.WebUI.Models
{
    public class Administration : AppUser
    {
        public Administration() { }
        public Administration(string employeeID)
            : base(employeeID) { }

        private List<KeyValuePair<long, Assignment>> _OverDueAssignments = null;
        public List<KeyValuePair<long, Assignment>> OverDueAssignments
        {
            get
            {
                if (_OverDueAssignments == null)
                {
                    _OverDueAssignments =
                        _AssignmentRepository.OverDueAssignmentsAssignedBy(EmployeeID).Select(a => new KeyValuePair<long, Assignment>((long)_AssignmentRepository.IdOf(a), a)).OrderBy(a => a.Value.DueDate).ToList();
                }
                return _OverDueAssignments;
            }
        }

        private List<KeyValuePair<long, Assignment>> _UncompletedAssignments = null;
        public List<KeyValuePair<long, Assignment>> UncompletedAssignments
        {
            get
            {
                if (_UncompletedAssignments == null)
                {
                    _UncompletedAssignments =
                        _AssignmentRepository.UncompletedAssignmentsAssignmentsAssignedBy(EmployeeID).Select(a => new KeyValuePair<long, Assignment>((long)_AssignmentRepository.IdOf(a), a)).OrderBy(a => a.Value.DueDate).ToList();
                }
                return _UncompletedAssignments;
            }
        }

        private List<KeyValuePair<long, Assignment>> _RecentlyCompletedAssignments = null;
        public List<KeyValuePair<long, Assignment>> RecentlyCompletedAssignments
        {
            get
            {
                if (_RecentlyCompletedAssignments == null)
                {
                    _RecentlyCompletedAssignments =
                        _AssignmentRepository.RecentlyCompletedAssignmentsAssignedBy(EmployeeID).Select(a => new KeyValuePair<long, Assignment>((long)_AssignmentRepository.IdOf(a), a)).OrderByDescending(a => a.Value.CompletedOn).ToList();
                }
                return _RecentlyCompletedAssignments;
            }
        }

        public void Delete(long assignmentId)
        {
            _AssignmentRepository.Remove(_AssignmentRepository[assignmentId]);
        }
    }
}