using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using wispro.sp.entity;
using wispro.sp.share;
using wispro.sp.web.Models;

namespace wispro.sp.web.Services
{
    public interface IProjectService
    {
        Task<List<ProjectInfo>> GetProjectInfos(int State);
        Task<List<ProjectInfo>> GetAllProjects();
        Task<List<ProjectContentRecord>> GetMyProjects();
        Task<bool> SetProjectFinish(string caseNo);

        Task<ApiSaveResponse> AddProjectPerformanctItem(ProjectContents projectPoint);

        Task<ProjectContents> getProjectWorkContent(int value);

        Task<ApiSaveResponse> SaveContent(ProjectContents task);

        Task<ApiSaveResponse> SubmitToReview(int Id, int ReviewerId);

        Task<List<ProjectContents>> GetProjectCanReviewWorkContent(string projectNo,CalMonth cal);
        Task<List<ProjectInfo>> GetWaitingReviewProjects();
        Task<ApiSaveResponse> ReviewProjectWorkContent(List<ProjectContents> projectContents);

        Task<List<ProjectContents>> GetProjectHistroy(string projectNo);
    }

    public class ProjectService : IProjectService
    {
        private readonly IHttpService _httpClient;

        public ProjectService(IHttpService httpClient)
        {
            _httpClient = httpClient;
        }

        public async Task<List<ProjectInfo>> GetProjectInfos(int State)
        {
            var data = await _httpClient.Get<List<ProjectInfo>>($"Project/GetProjects?state={State}");
            return data;
        }

        public async Task<List<ProjectInfo>> GetAllProjects()
        {
            var data = await _httpClient.Get<List<ProjectInfo>>($"Project/GetAll");
            return data;
        }
        public async Task<List<ProjectContentRecord>> GetMyProjects()
        {
            var data = await _httpClient.Get<List<ProjectContentRecord>>($"Project/GetMyProjects");
            return data;
        }

        public async Task<bool> SetProjectFinish(string caseNo)
        {
            var data = await _httpClient.Get<bool>($"Project/SetFinished?CaseNo={caseNo}");
            return data;
        }

        public async Task<ApiSaveResponse> AddProjectPerformanctItem(ProjectContents projectPoint)
        {
            var data = await _httpClient.Post<ApiSaveResponse>($"PerformanceItem/AddProjectPerformance", projectPoint);
            return data;
        }

        public async Task<ProjectContents> getProjectWorkContent(int value)
        {
            var data = await _httpClient.Get<ProjectContents>($"Project/getProjectWorkContent?Id={value}");
            return data;
        }

        public async Task<ApiSaveResponse> SaveContent(ProjectContents task)
        {
            var response = await _httpClient.Post<ApiSaveResponse>("Project/SaveProjectWorkContent", task);
            return response;
        }

        public async Task<ApiSaveResponse> SubmitToReview(int Id, int ReviewerId)
        {
            var data = await _httpClient.Get<ApiSaveResponse>($"Project/SubmitToReview?Id={Id}&&reviewerId={ReviewerId}");
            return data;
        }

        public async Task<List<ProjectContents>> GetProjectCanReviewWorkContent(string projectNo,CalMonth cal)
        {
            var strUrl = $"Project/GetProjectCanReviewWorkContent?projectNo={projectNo}&&year={cal.Year}&&month={cal.Month}";
            

            var data = await _httpClient.Get<List<ProjectContents>>(strUrl);
            return data;
        }

        public async Task<List<ProjectInfo>> GetWaitingReviewProjects()
        {
            var data = await _httpClient.Get<List<ProjectInfo>>($"Project/GetWaitingReviewProject");
            return data;
        }

        public async Task<List<ProjectContents>> GetProjectHistroy(string projectNo)
        {
            var data = await _httpClient.Get<List<ProjectContents>>($"Project/GetProjectHisttory?projectNo={projectNo}");
            return data;
        }

        public async Task<ApiSaveResponse> ReviewProjectWorkContent(List<ProjectContents> projectContents)
        {
            var response = await _httpClient.Post<ApiSaveResponse>("Project/ReviewProjectWorkContent", projectContents);
            return response;
        }

       
    }
}