package com.gic.haoban.manage.web.controller.goods;

import com.gic.haoban.app.aggregation.api.dto.GoodsSettingDTO;
import com.gic.haoban.app.aggregation.api.service.SettingApiService;
import com.gic.haoban.manage.web.qo.content.ContentMaterialQO;
import com.gic.store.goods.service.GoodsInfoOutApiService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author MUSI
 * @Date 2023/3/16 10:19 PM
 * @Description
 * @Version
 **/

@Component
public class GoodsInfoAdaptor {

    @Autowired
    private SettingApiService settingApiService;
    @Autowired
    private GoodsInfoOutApiService goodsInfoOutApiService;

    public List<String> queryGoodsIdWithSearch(String enterpriseId, String search) {
        // 根据关键字查询1000个商品

        return Collections.emptyList();
    }

    /**
     * 查询好办商品展示的商品状态
     *
     * @param enterpriseId
     * @return
     */
    public List<Integer> getGoodsShowStatus(String enterpriseId) {
        if (StringUtils.isBlank(enterpriseId)) {
            return Collections.emptyList();
        }
        GoodsSettingDTO goodsSettingDTO = settingApiService.getSetting(enterpriseId);
        List<Integer> showStatus = new ArrayList<>();
        if (goodsSettingDTO != null) {
            int salesGoodsFlag = goodsSettingDTO.getSalesGoodsFlag();
            int notSalesGoodsFlag = goodsSettingDTO.getNotSalesGoodsFlag();
            if (salesGoodsFlag == 1 && notSalesGoodsFlag == 1) {
                //已上架和未上架
                showStatus.add(1);
                showStatus.add(2);
            } else if (salesGoodsFlag == 1) {
                //已上架
                showStatus.add(1);
            } else if (notSalesGoodsFlag == 1) {
                //未上架
                showStatus.add(2);
            } else {
                //啥都未打开
                showStatus.add(-99);
            }
        } else {
            // 默认展示已上架和未上架的数据
            showStatus.add(1);
            showStatus.add(2);
        }
        return showStatus;
    }
}
