using Common.Dtos;
using Common.Dtos.Exper;
using System.Net.Http.Json;

namespace HushianWebApp.Service
{
    public class UserService
    {
        private readonly BaseController _baseController;
        const string BaseRoute = "v1/Exper/";

        public UserService(BaseController baseController)
        {
            _baseController = baseController;
        }
        public async Task<bool> AddExper(ADD_ExperDto request)
        {
            var response = await _baseController.Post($"{BaseRoute}AddExper", request);
            return response.IsSuccessStatusCode;
        }
        public async Task<List<Read_ExperDto>?> GetExpersCompany()
        {
            string route = $"{BaseRoute}GetExpersCompany";
            //&PageIndex={PageIndex}&PageSize={PageSize}
            var response = await _baseController.Get(route);
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadFromJsonAsync<List<Read_ExperDto>>();
            }
            return null;
        }
        public async Task<List<Read_ExperDto>?> GetExpersCompany(int CompanyID)
        {
            string route = $"{BaseRoute}GetExpersCompany?CompanyID={CompanyID}";
            var response = await _baseController.Get(route);
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadFromJsonAsync<List<Read_ExperDto>>();
            }
            return null;
        }

        //--------------------------------------------------------------------------------------------------------------
        public async Task<bool> EditUserYourself(Update_ExperDto request) //ویرایش کاربران توسط خود
        {
            var response = await _baseController.Put($"{BaseRoute}EditUserYourself", request);
            return response.IsSuccessStatusCode;
        }
        public async Task<Read_ExperDto?> GetCurrentExper() //ویرایش کاربران توسط خود
        {
            var response = await _baseController.Get($"{BaseRoute}GetCurrentExper");
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadFromJsonAsync<Read_ExperDto>();
            }
            return null;
        }
        public async Task<bool> ExperEditingFromManager(int ExperID,Update_ExperDto request) //ویرایش کاربران توسط مدیرش
        {
            var response = await _baseController.Put($"{BaseRoute}ExperEditingFromManager/{ExperID}", request);
            return response.IsSuccessStatusCode;
        }

        public async Task<bool> ChangePasswordYourself(ChangePasswordDto request) //تغییر کلمه عبور  کاربران توسط خود
        {
            var response = await _baseController.Put($"{BaseRoute}ChangePasswordYourself", request);
            return response.IsSuccessStatusCode;
        }
        public async Task<bool> ChangePasswordFromManager(int ExperID, ChangePasswordDto request) //تغییر کلمه عبور  کاربران توسط خود
        {
            var response = await _baseController.Put($"{BaseRoute}ChangePasswordFromManager/{ExperID}", request);
            return response.IsSuccessStatusCode;
        }
        public async Task<bool> CheckAvailableExperInCompany(string? ExperID=null) 
        {
            string route = $"{BaseRoute}CheckAvailableExperInCompany";
            if (!string.IsNullOrEmpty(ExperID))
                route += $"?ExperID={ExperID}";
            var response = await _baseController.Get(route);
            return response.IsSuccessStatusCode;
        }


        public async Task<bool> ChangeAvailableExperFromManager(int ExperID,bool Available)
        {
            var response = await _baseController.Put($"{BaseRoute}ChangeAvailableExperFromManager/{ExperID}?Available={Available}");
            return response.IsSuccessStatusCode;
        }

        public async Task<bool>DeleteExperFromManager(int ExperID)
        {
            var response = await _baseController.Delete($"{BaseRoute}DeleteExperFromManager/{ExperID}");
            return response.IsSuccessStatusCode;
        }
        public async Task<CurrentUserInfo> GetCurrentUserInfo()
        {
            var response = await _baseController.Get($"{BaseRoute}GetCurrentUserInfo");
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadFromJsonAsync<CurrentUserInfo>();
            }
            return null;
        }

       


    }
}
