using Microsoft.AspNetCore.Mvc;
using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.Model.ApiModel.MatInventoryDetail;
using WCS.Model;
using WCS.Model.ApiModel.StoreInfo;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.DAL.DbModels;
using WCS.WebApi.Helper;

namespace WCS.WebApi.Controllers
{
    /// <summary>
    /// 货架管理
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    public class StoreInfoController : ControllerBase
    {
        public IStoreInfoService _storeInfoService { get; set; }
        public StoreInfoController(IStoreInfoService storeInfoService)
        {
            _storeInfoService = storeInfoService;
        }

        #region 货架管理
        [Route("getShelves")]
        [HttpPost(Name = "getShelves")]
        public async Task<ResponseBase> getShelves(GetShelvesRequest request)
        {
            return await _storeInfoService.GetShelves(request);
        }
        [Route("exportShelves")]
        [HttpPost(Name = "exportShelves")]
        public async Task<IActionResult> exportShelves(GetShelvesRequest request)
        {
            var result = await _storeInfoService.ExportShelves(request);
            var data = result.Data?.Lists;
            var columns = new[]
            {
                new ExportableColumn("序号","RowNumber"),
                new ExportableColumn("货架类型","ShelfTypeName"),
                new ExportableColumn("货架编号","ShelfCode"),
                new ExportableColumn("货架尺寸","ShelfSize"),
                new ExportableColumn("备注","Remark"),
                new ExportableColumn("货架当前状态","ShelfStatus"),
                new ExportableColumn("启用状态","IsEnableStr"),
                new ExportableColumn("更新人", "ModifyUser"),
                new ExportableColumn("更新时间", "ModifyTime"),
            };
            if (data == null)
            {
                return NotFound();
            }
            else
                return ExportExcelHelper.Export("导出数据", columns, data);
        }

        [HttpPost("addOrUpdateShelfInfo")]
        public async Task<ResponseCommon<object>> addOrUpdateShelfInfo(AddShelfInfoRequest<ShelfInfo> request)
        {
            return await _storeInfoService.addOrUpdateShelfInfo(request);
        }

        [HttpPost("deleteShelfInfo")]
        public async Task<ResponseCommon<object>> deleteShelfInfo(DeleteInfosRequest request)
        {
            return await _storeInfoService.deleteShelfInfo(request);
        }
        #endregion

        #region 库位管理
        [Route("getStores")]
        [HttpPost(Name = "getStores")]
        public async Task<ResponseBase> getStores(GetStoresRequest request)
        {
            return await _storeInfoService.GetStores(request);
        }
        #endregion
    }
}
