using Back.Services;
using Back.Services.Warehouse;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Back.Controllers.Warehouse
{
    [Route("api/[controller]")]
    [Authorize]
    [ApiController]
    public class WarehouseController : ControllerBase
    {
        private readonly WarehouseService _warehouseService;
        private readonly servUser _servUser;

        public WarehouseController(WarehouseService warehouseService, servUser servUser)
        {
            _warehouseService = warehouseService;
            _servUser = servUser;
        }

        [HttpGet("Circulation")]
        public async Task<IActionResult> Circulation(string date = "", int CODID = 0, int PageIndex = 1, int PageSize = 5)
        {
            var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
            var UserID = claim.Value;
            var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
            var CompanyID = user.RolUsers.First().CompanyID;
            return Ok(await _warehouseService.Circulation(CompanyID,date,CODID,PageIndex,PageSize));
        }
        [HttpGet("Inventory/{CODID}")]
        public async Task<IActionResult> Inventory(int CODID)
        {
            var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
            var UserID = claim.Value;
            var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
            var CompanyID = user.RolUsers.First().CompanyID;
            return Ok(await _warehouseService.Inventory(CompanyID, CODID));
        }
    }
}
