package org.dromara.zhishu.service;

import jakarta.validation.constraints.NotNull;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.SysUser;
import org.dromara.zhishu.domain.StockChangeLog;
import org.dromara.zhishu.domain.Task;
import org.dromara.zhishu.domain.ZhishuShopGoods;
import org.dromara.zhishu.domain.bo.BatchUpdateCargoBo;
import org.dromara.zhishu.domain.bo.TaskBo;
import org.dromara.zhishu.domain.bo.ZhishuShopGoodsBo;
import org.dromara.zhishu.domain.dto.request.BatchGoodsRequest;
import org.dromara.zhishu.domain.dto.request.GoodsComparisonRequest;
import org.dromara.zhishu.domain.vo.*;
import org.dromara.zhishu.domain.vo.ProductSubmitResultVo;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 商品信息Service接口
 *
 * @author Lion Li
 * @date 2025-03-07
 */
public interface IZhishuShopGoodsService {

    /**
     * 批量查询商品根据id
     * @param ids
     * @return
     */
    List<ZhishuShopGoodsVo> selectByIds(List<String> ids);

    /**
     * 查询商品信息
     *
     * @param id 主键
     * @return 商品信息
     */
    ZhishuShopGoodsVo queryById(String id);

    /**
     * 根据isbn查询商品信息
     *
     * @param isbn 主键
     * @return 商品信息
     */
    List<ProductVo> getProductByBarcode(String isbn);

    /**
     * 根据商品编码查询信息
     *
     * @param itemNumber
     * @return
     */
    ZhishuShopGoodsVo selectShopGoodsByItemNumber(String itemNumber);


    /**
     * 根据货号查询商品
     *
     * @param artNo
     * @return
     */
    ZhishuShopGoodsVo selectShopGoodsByArtNo(String artNo);

    /**
     * 提交商品信息
     *
     * @param form 商品信息表单
     */
    ProductSubmitResultVo submitProduct(ProductForm form);

    /**
     * 上传商品照片
     *
     * @param photos 照片文件列表
     */
    void uploadPhotos(MultipartFile[] photos);

    /**
     * 分页查询商品信息列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 商品信息分页列表
     */
    TableDataInfo<ZhishuShopGoodsVo> queryPageList(ZhishuShopGoodsBo bo, PageQuery pageQuery);

    /**
     * 查询符合条件的商品信息列表
     *
     * @param bo 查询条件
     * @return 商品信息列表
     */
    List<ZhishuShopGoodsVo> queryList(ZhishuShopGoodsBo bo);

    /**
     * 新增商品信息
     *
     * @param bo 商品信息
     * @return 是否新增成功
     */
    Boolean insertByBo(ZhishuShopGoodsBo bo);

    /**
     * 批量新增商品信息
     *
     * @param list 商品列表
     */
    Boolean insertList(List<ZhishuShopGoodsBo> list, Long depotid, String Filename);

    /**
     * 自营书品批量新增商品信息
     *
     * @param list 商品列表
     */
    Boolean insertListGoodsInfo(List<ZhishuShopGoodsBo> list, Long depotId, Long shelvesDepotId, Long freightDepotId, String Filename, String code ,Long userId,String type);

    /**
     * 修改商品信息
     *
     * @param bo 商品信息
     * @return 是否修改成功
     */
    Boolean updateByBo(ZhishuShopGoodsBo bo);

    /**
     * 校验并批量删除商品信息信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid);

    /**
     * 通过孔夫子网站API查询图书信息
     *
     * @param isbn ISBN编号
     * @return 图书信息
     */

    List<KongfzVo> getProductByKongfz(String isbn, String searchType, String sortType, String conditionValue, String cookies, String publisher, String author);

    /**
     * 初始化库存到redis
     */
    void batchInitInventoryToRedis();

    void batchRedisInitInventory(List<ZhishuShopGoods> goodsList);

    /**
     * 操作库存
     *
     * @param shopGoodsId
     * @param count
     * @return
     */
    Boolean operatingInventory(Integer operationType, String shopGoodsId, Integer count, Integer type, String aboutId, Long operationBy);

    ProductVo queryBookByPython(String isbn);

//    List<ZhishuShopGoodsVo> selectShopGoodsByPhoneNumber(String phoneNumber,);

    /**
     * 库存比对存入表格
     *
     * @param request
     */
    void goodsComparison(GoodsComparisonRequest request);

    /**
     * 批量库存比对存入表格
     *
     * @param request
     */
    void batchGoodsComparison(BatchGoodsRequest request);

    /**
     * 根据用户选择货号规则将商品存入数据库
     */
    void saveShopGoodsInDb(SaveGoodsVo saveGoodsVo);

    ProductForm repeatBook(ProductForm form);

    /**
     * 根据库存操作类型操作库存并同步平台库存
     *
     * @param operationType
     * @param shopGoodsPublishedVo
     * @param count
     */
    Boolean operatingGoodsInventory(Long shopId, Integer shopType, Integer operationType, ShopGoodsPublishedVo shopGoodsPublishedVo, Integer count, String orderSn);


    Boolean goofishoperatingGoodsInventory(Long shopId, Integer shopType, Integer operationType, ZhishuShopGoodsVo zhishuShopGoodsVo, Integer count, String orderSn);




    void randomUpdateArtNo(Long userId, Long shopId);

    void goodsAdd(Map map);

    void goodsAutoAdd(Map map);


    void goodsAdd(Map map, Long userId,ShopVo shopVo);

    int zanTing(String threadId);

    int huanXing(String threadId);

    String artNoProcessing(Integer saveArtNoRule, Long userId, String isbn, String oldArtNo, double conditionCode, FreightGoodsCountVo freightGoodsCountVo);

    List<StockChangeLogVo> selectShopStockLog(String id);

    Integer queryInventory(@NotNull(message = "商品Id不能为空") Long shopGoodsId);

    ProductSubmitResultVo submitFromCopyrightPage(ProductForm form);

    List<AuthorPressVo> getAuthorAndPublisher(String keyword, String cookies);

    TableDataInfo<ZhishuShopGoodsVo> selectShopGoodsByPhoneNumber(String phoneNumber, int pageNum, int pageSize, String date);

    Map selectDepotIds(String userId, String artNo);

    StockChangeLog queryStockChangeLogByOrderSn(@NotNull(message = "平台订单编码不能为空") String orderSn, @NotNull(message = "库存操作日志类型不能为空") Integer type);

    /**
     * 根据用户ID查询商品数量
     *
     * @param userId 用户ID
     * @return 商品数量
     */
    Long queryGoodsCountByUserId(Long userId);

    SysUser  queryUserByUserId(@NotNull(message = "店铺ID不能为空") Long userId);

    Boolean operatingGoodsSoldOut(Long shopId, Integer platformType, Integer logType, Integer operationType, ShopGoodsPublishedVo shopGoodsPublishedVo, String orderSn);

    TableDataInfo<ZhishuShopGoodsVo> queryGoodListByArtNo(String code, Long userId, int pageNum, int pageSize, String date);

    /**
     * 批量移动商品位置
     *
     * @param itemIds 商品ID列表
     * @param warehouse 货区编码
     * @param shelf 货架编码
     * @param freight 货位编码
     * @param userId 用户ID
     * @return 操作结果
     */
    String batchMoveItems(List<String> itemIds, String warehouse ,String shelf, String freight, Long userId);


    int batchUpdateCargo(BatchUpdateCargoBo bo);

    /**
     * 根据货号前缀 分页  修改 分销状态
     * @param isJoinDistribution
     * @param artNoPrefix
     * @param userId
     * @param limitNum
     * @return
     */
    int updateByArtNoPrefix(String isJoinDistribution,String artNoPrefix,Long userId, Long limitNum);

    void createShopGoodsList(BatchGoodsRequest request);

    void deleteTaskDataByShopId(Long shopId);

    void syncRunningTaskToShopGoods(@NotNull(message = "店铺ID不能为空") Long shopId, Long freightId, Long userId, TaskBo taskBo);

    void synchronousTask(ShopVo shopVo, TaskBo taskBo);

    Map uploadImg(MultipartFile file);

    void synShopImg(Long userId);

    void synPddShopImg(Long userId);

    Long getTaskDataNum(Long taskId);

//    void batchUpdateCargo(BatchUpdateCargoBo bo);
}
