using BPA.Franchisee.Application.FranchiseeCenter.GoodsServices;
using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods;
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute;
using BPA.SAAS.Manage.Application.DataBase.Interface;
using BPA.SAAS.Manage.Core.Base;
using BPA.SAAS.Manage.Core.DataBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.DataBase
{
    [ApiDescriptionSettings("Goods", Tag = "商品管理")]
    public class GoodsServices: IDynamicApiController, ITransient
    {
        IGoodsService _goodsService;
        public GoodsServices(IGoodsService goodsService)
        {
            _goodsService=goodsService;
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/page")]
        public async Task<PageUtil> GetGoodsPage(GoodsQueryDto dto)
        {
            return await _goodsService.GetGoodsPage(dto);
        }
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/add")]
        public async Task<bool> AddGoods(GoodsDto dto)
        {
            return await _goodsService.AddGoods(dto);
        }
        /// <summary>
        /// 更新商品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/update")]
        public async Task<bool> UpdateGoods(GoodsDto dto)
        {
            return await _goodsService.UpdateGoods(dto);
        }
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("/api/goods/delete")]
        public async Task<bool> DeleteGoods(string id)
        {
            return await _goodsService.DeleteGoods(id);
        }
        /// <summary>
        /// 查询商品单位
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/goods/getgoodsuintlist")]
        public async Task<List<dynamic>> GetGoodsUintList()
        {
            return await _goodsService.GetGoodsUintList();
        }
        /// <summary>
        /// 查询商品单位(外部调用)
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/goods/getgoodsuintlist_alm")]
        [AllowAnonymous]
        public async Task<List<dynamic>> GetGoodsUintList_alm()
        {
            return await _goodsService.GetGoodsUintList_alm();
        }
        /// <summary>
        /// 添加商品单位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/addgoodsuint")]
        public async Task<bool> AddGoodsUint(GoodsUintDto dto)
        {
            return await _goodsService.AddGoodsUint(dto);
        }
        /// <summary>
        /// 商品配方
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/getgoodsbompage")]
        public async Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto)
        {
            return await _goodsService.GetGoodsBomPageAsync(dto);
        }
        /// <summary>
        /// 删除商品配方
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        [HttpGet("/api/goods/delgoodsbom")]
        public async Task<bool> BatchDelGoodsBomAsync(string Ids)
        {
            return await _goodsService.BatchDelGoodsBomAsync(Ids);
        }
        /// <summary>
        /// 添加商品配方(包含属性关系)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/addgoodsbomattribute")]
        public async Task<bool> AddGoodsBomAttribute(GoodsBomAttributeDto dto)
        {
            return await _goodsService.AddGoodsBomAttribute(dto);
        }
        /// <summary>
        /// 添加商品配方
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/addgoodsbom")]
        public async Task<bool> AddGoodsBom(GoodsBomDto dto)
        {
            return await _goodsService.AddGoodsBom(dto);
        }
        /// <summary>
        /// 查询所有商品
        /// </summary>
        /// <returns></returns>
        [HttpGet("/api/goods/getgoodslist")]
        public async Task<List<BPA_GoodsInfo>> GetGoodsList()
        {
            return await _goodsService.GetGoodsList();
        }
        /// <summary>
        /// 根据id查询商品信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("/api/goods/getbyidgoods")]
        public async Task<GoodsInfoBaseView> GetGoods(string id)
        {
            return await _goodsService.GetGoods(id);
        }

        /// <summary>
        /// 更具id查询商品信息列表
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost("/api/goods/GetGoodsListByIds")]
        public async Task<List<GoodsInfoBaseView>> GetGoodsListByIds(List<string> ids)
        {
            return await _goodsService.GetGoodsListByIds(ids);
        }

        ///// <summary>
        ///// 设备上传商品数据
        ///// </summary>
        ///// <param name="goodsDatadto"></param>
        ///// <returns></returns>
        //Task<bool> SendGoodsInfo(GoodsDatadto goodsDatadto);
        [HttpPost("/api/goods/exportgood"), ApiDescriptionSettings(SplitCamelCase = false), NonUnify]
        public async  Task<bool> ExportGood(IFormFile file)
        {
            return await _goodsService.ExportGood(file);
        }

        /// <summary>
        /// 导出 设备工艺流程
        /// </summary>
        /// <returns></returns>
        [HttpPost("/api/goods/technologytemplateexport"), NonUnify]
        public async  Task<string> TechnologyTemplateExport(string deviceId)
        {
            return await _goodsService.TechnologyTemplateExport(deviceId);
        }

        /// <summary>
        /// 设备 版本 工序模型导入
        /// </summary>
        /// <returns></returns>
        [HttpPost("/api/goods/goodstemplateexport"), NonUnify]
        public async Task<bool> DeviceVersionTemplateImport([FromForm] DeviceVersionTemplateImportInputDto inputDto)
        {
            return await _goodsService.DeviceVersionTemplateImport(inputDto);
        }
    }
}
