package com.slodon.b2b2c.controller.api.seller;

import java.util.List;

import com.slodon.b2b2c.core.controller.BaseController;
import com.slodon.b2b2c.core.response.JsonResult;
import com.slodon.b2b2c.core.response.SldResponse;
import com.slodon.b2b2c.model.api.EnquiryApiModel;
import com.slodon.b2b2c.model.api.GoodsApiModel;
import com.slodon.b2b2c.vo.api.APIRequestVO;
import com.slodon.b2b2c.vo.api.EnquiryPageVO;
import com.slodon.b2b2c.vo.api.ProductInfoVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Api(tags = "seller-对外接口")
@RestController
@RequestMapping("/openapi")
@Slf4j
public class OpenAPIController extends BaseController {

    @Resource private GoodsApiModel goodsApiModel;

    @Resource private EnquiryApiModel enquiryApiModel;


    /** 外部api请求获取产品列表 */
    @PostMapping("/product/list")
    @ResponseBody
    public JsonResult<List<ProductInfoVO>> listProducts(
            @RequestBody APIRequestVO apiRequest) {
        log.info("苏豪通请求该商家产品列表 parameter: {}", apiRequest.getStoreId());
        List<ProductInfoVO> list = goodsApiModel.getGoodsByStoreId(apiRequest.getStoreId());
        if (!CollectionUtils.isEmpty(list)) {
            return SldResponse.success(list);
        } else {
            return SldResponse.fail("No product information found for this store");
        }
    }

    /** 外部api请求获取询盘列表 */
    @PostMapping("/enquiry/list")
    @ResponseBody
    public JsonResult<EnquiryPageVO> listEnquires(
            @RequestBody APIRequestVO apiRequest) {
        log.info("苏豪通请求该商家产品列表 parameter: {}", apiRequest.getStoreId());
        EnquiryPageVO enquiryPage = enquiryApiModel.getEnquiryByStoreId(apiRequest);
        if (enquiryPage!=null) {
            return SldResponse.success(enquiryPage);
        } else {
            return SldResponse.fail("No enquiry information was found for this store");
        }
    }


}
