package com.fzm.mall.server.front.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.fzm.mall.server.front.base.ResponseVO;
import com.fzm.mall.server.front.constant.MallResponseEnum;
import com.fzm.mall.server.front.goods.model.*;
import com.fzm.mall.server.front.goods.model.vo.*;
import com.fzm.mall.server.front.goods.service.*;
import com.fzm.mall.server.front.merchant.model.Merchant;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mall/homePage")
public class HomePageController {

    @Autowired
    private IBannerService bannerService;

    @Autowired
    private ICountService countService;

    @Autowired
    private ICustomService customService;

    @Autowired
    private IFlashSaleService flashSaleService;

    @Autowired
    private ILowPriceService lowPriceService;

    @Autowired
    private IHotService hotService;

    @Autowired
    private ISaleHotService saleHotService;

    @Autowired
    private IFunctionService functionService;

    @Autowired
    private IOprationFunctionService iOprationFunctionService;

    @Autowired
    private IOprationBannerService iOprationBannerService;

    @Autowired
    private IOprationFloorService oprationFloorService;

    @Autowired
    private IOprationFloorGoodsService oprationFloorGoodsService;

    public static final String PLATFORM_MERCHANT_ID = "e3ac4b4a4e65460dbd9f1ec6cbd7a900";

    @ApiOperation(value = "获取banner")
    @PostMapping("/without/getBanner")
    public ResponseVO<List<OprationBanner>> getBanner(){
        List<OprationBanner> banners = iOprationBannerService.getList(PLATFORM_MERCHANT_ID);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,banners);
    }

    @ApiOperation(value = "获取楼层")
    @PostMapping("/without/getFloor")
    public ResponseVO<List<OprationFloor>> getFloor(){
        List<OprationFloor> oprationFloors = oprationFloorService.getFloor();
        return  new ResponseVO<>(MallResponseEnum.SUCCESS,oprationFloors);
    }

    @ApiOperation(value = "店家推荐")
    @PostMapping("/without/getRecommend")
    public ResponseVO<GoodsViewVo> getRecommend(@RequestBody PageVo pageVo){
        List<SaleHotVo> saleHotVos = countService.getList(pageVo);
        int count = countService.getCount();
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }



    @ApiOperation(value = "获取秒杀商品")
    @PostMapping("/without/getFlashSale")
    public ResponseVO<List<GoodsFlashVo>> getFlashSale(@RequestBody String merchantId, @RequestBody PageVo pageVo){
        List<GoodsFlashVo> goodsFlashVos =  flashSaleService.getlist(merchantId,pageVo);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsFlashVos);
    }
    @ApiOperation(value = "获取楼层商品 ")
    @PostMapping("/without/getFloorGoods")
    public ResponseVO<GoodsViewVo> getFloorGoods(@RequestBody PageVoWithOne pageVoWithOne){
        String operationFloorId = pageVoWithOne.getParam();
        List<SaleHotVo> saleHotVos = oprationFloorGoodsService.getByOperationFloorId(operationFloorId,pageVoWithOne);
        Integer count = oprationFloorGoodsService.getCount(operationFloorId);
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }
/*

    @ApiOperation(value = "平台推荐")
    @PostMapping("/without/getCustom")
    public ResponseVO<GoodsViewVo> getCustom(@RequestBody PageVo pageVo){
        List<SaleHotVo> saleHotVos = customService.getList(pageVo);
        int count = customService.getCount();
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }

    @ApiOperation(value = "低价好货")
    @PostMapping("/without/getLowPrice")
    public ResponseVO<GoodsViewVo> getLowPrice(@RequestBody PageVo pageVo){
        List<SaleHotVo> saleHotVos = lowPriceService.getList(pageVo);
        int count = lowPriceService.getCount();
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }

    @ApiOperation(value = "热销好货")
    @PostMapping("/without/getHot")
    public ResponseVO<GoodsViewVo> getHot(@RequestBody PageVo pageVo){
        List<SaleHotVo> saleHotVos = hotService.getList(pageVo);
        int count = hotService.getCount();
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }


    @ApiOperation(value = "爆款抢购")
    @PostMapping("/without/getSaleHot")
    public ResponseVO<GoodsViewVo> getSaleHot(@RequestBody PageVo pageVo){
        List<SaleHotVo> saleHotVos = saleHotService.getList(pageVo);
        int count = saleHotService.getCount();
        GoodsViewVo goodsViewVo = new GoodsViewVo();
        goodsViewVo.setList(saleHotVos);
        goodsViewVo.setTotal(count);
        return new ResponseVO<>(MallResponseEnum.SUCCESS,goodsViewVo) ;
    }
*/

    @ApiOperation(value = "获取首页功能区")
    @PostMapping("/without/getFunction")
    public ResponseVO<List<OprationFunction>> getFunction(){
        List<OprationFunction> functions = iOprationFunctionService.getOprationFunction();
        return  new ResponseVO<>(MallResponseEnum.SUCCESS,functions);
    }


}
