using System;
using System.ServiceModel.DomainServices.Client;
using TaskIt.Web;
using TaskIt.Web.Services;

namespace TaskIt.Core
{
    public class DataService : IDataService
    {
        public LoadOperation<Project> GetProjects(long userID, Action<LoadOperation<Project>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetProjectsQuery(userID), loadOperation, null);
        }

        public LoadOperation<Context> GetContexts(long userID, Action<LoadOperation<Context>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetContextsQuery(userID), loadOperation, null);
        }

        public LoadOperation<Contact> GetContacts(long userID, Action<LoadOperation<Contact>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetContactsQuery(userID), loadOperation, null);
        }

        public LoadOperation<TaskItUser> GetUsers(Action<LoadOperation<TaskItUser>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetUsersQuery(), loadOperation, null);
        }

        public LoadOperation<TaskCategory> GetTaskCategories(Action<LoadOperation<TaskCategory>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTaskCategoriesQuery(), loadOperation, null);
        }

        public LoadOperation<Priority> GetPriorities(Action<LoadOperation<Priority>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetPrioritiesQuery(), loadOperation, null);
        }

        public LoadOperation<Task> GetAllTasks(long userID, bool status, bool isCalendarView, Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetAllTasksQuery(userID, status, isCalendarView), loadOperation, false);
        }

        public LoadOperation<Task> GetTasksByCategory(long userID, long filterInfoID, bool showCompleted, bool showDue, Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTasksByTaskCategoryQuery(userID, filterInfoID, showCompleted, showDue), loadOperation, false);
        }

        public LoadOperation<Task> GetTasksByProject(long userID, long filterInfoID, bool status, bool isCalendarView, Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTasksByProjectQuery(userID, filterInfoID, status, isCalendarView), loadOperation, false);
        }

        public LoadOperation<Task> GetTasksByContext(long userID, long filterInfoID, bool status, bool isCalendarView, Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTasksByContextQuery(userID, filterInfoID, status, isCalendarView), loadOperation, false);
        }

        public LoadOperation<Task> GetTasksByContact(long userID, long filterInfoID, bool status, bool isCalendarView, Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTasksByContactQuery(userID, filterInfoID, status, isCalendarView), loadOperation, false);
        }

        public LoadOperation<TaskNote> GetTaskNotes(long taskID, Action<LoadOperation<TaskNote>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetTaskNotesQuery(taskID), loadOperation, null);
        }

        public LoadOperation<ProjectNote> GetProjectNotes(long projectID, Action<LoadOperation<ProjectNote>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetProjectNotesQuery(projectID), loadOperation, null);
        }

        public LoadOperation<ContextNote> GetContextNotes(long contextID, Action<LoadOperation<ContextNote>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetContextNotesQuery(contextID), loadOperation, null);
        }

        public LoadOperation<ContactNote> GetContactNotes(long contactID, Action<LoadOperation<ContactNote>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetContactNotesQuery(contactID), loadOperation, null);
        }

        public LoadOperation<Task> GetOverdueTasks(long userID, Action<LoadOperation<Task>> loadOperation)
        {            
            return Utils.DataContext.Load(Utils.DataContext.GetOverdueTasksQuery(userID), loadOperation, null);
        }

        public LoadOperation<Project> GetProjectsDueThisWeek(long userID, Action<LoadOperation<Project>> loadOperation)
        {            
            return Utils.DataContext.Load(Utils.DataContext.GetProjectsDueThisWeekQuery(userID), loadOperation, null);
        }

        public LoadOperation<Task> GetTasksDueThisWeek(DataContext dataContext, long userID, Action<LoadOperation<Task>> loadOperation)
        {            
            return dataContext.Load(dataContext.GetTasksDueThisWeekQuery(userID), loadOperation, null);
        }

        //public LoadOperation<TasksOverview> GetTasksOverview(long userID, Action<LoadOperation<TasksOverview>> loadOperation)
        //{
        //    return Utils.DataContext.Loa((Utils.DataContext.GetTasksOverviewQuery(), loadOperation, null);
        //}

        public LoadOperation<Task> GetCompletedBlogPosts(Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetCompletedBlogPostsQuery(), loadOperation, null);
        }

        public LoadOperation<Task> GetCompletedVideos(Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetCompletedVideosQuery(), loadOperation, null);
        }

        public LoadOperation<Task> GetCompletedWebinars(Action<LoadOperation<Task>> loadOperation)
        {
            return Utils.DataContext.Load(Utils.DataContext.GetCompletedWebinarsQuery(), loadOperation, null);
        }

        public InvokeOperation<int> GetTaskCountForContext(long id, Action<InvokeOperation<int>> loadOperation)
        {
            return Utils.DataContext.GetTaskCountForContext(id);
        }
    }
}
