using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.Component.Jwt.UserClaim;
using MS.Models.ViewModel;
using MS.Services;
using MS.WebCore.Core;
using System;
using System.Threading.Tasks;

namespace MS.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IAccountService _accountService;
        private readonly IHttpContextAccessor _httpContextAccessor;
        public AccountController(IAccountService accountService, IHttpContextAccessor httpContextAccessor)
        {
            _accountService = accountService;
            _httpContextAccessor = httpContextAccessor;
        }
        //[AllowAnonymous]
        [Route("sadas")]
        [HttpPost]
        public async Task<ExecuteResult> Post()
        {
            return null;
        }
        [HttpPost]
        //[AllowAnonymous]
        public async Task<ExecuteResult<UserData>> Login(LoginViewModel viewModel)
        {
            return await _accountService.Login(viewModel);
        }
        [Route("syncFromVersion")]
        [HttpPost]
        [AllowAnonymous]
        public async Task<ExecuteResult<UserData>> syncFromVersion(long versionNo,bool excludingCurrentBu)
        {
            var context = _httpContextAccessor.HttpContext;
            var allHeaders = context.Request.Headers; // 获取所有请求头
            var specificHeader = context.Request.Headers["DeviceSN"].ToString(); // 获取指定请求头
        
            return await _accountService.syncFromVersion(versionNo, excludingCurrentBu, specificHeader);
        }
        [Route("AddEmployeeCardMonthlySummaryToRedisAsync")]
        [HttpPost]
        [AllowAnonymous]
        public async Task<bool> AddEmployeeCardMonthlySummaryToRedisAsync(string buid, string date)
        {
            Guid ssss = Guid.NewGuid();

             await _accountService.AddEmployeeCardMonthlySummaryToRedisAsync(buid,date);
            return true;
        }
        [Route("ClearhashValues")]
        [HttpPost]
        [AllowAnonymous]
        public async Task<bool> ClearhashValues(string key)
        {
            await _accountService.ClearhashValues(key);
            return true;
        }
    }
}