package com.buy507.mall.portal.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.buy507.mall.common.api.CommonResult;
import com.buy507.mall.model.PmsProduct;
import com.buy507.mall.portal.domain.HomeContentResult;
import com.buy507.mall.portal.domain.ProductCategoryOptions;
import com.buy507.mall.portal.domain.ProductDetailResult;
import com.buy507.mall.portal.domain.ProductSkuResult;
import com.buy507.mall.portal.service.HomeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 首页内容管理Controller
 */
@RestController
@Api(tags = "HomeController", description = "首页内容管理")
@RequestMapping("/home")
public class HomeController {

	@Autowired
	private HomeService homeService;

	@ApiOperation("首页内容页信息展示")
	@RequestMapping(value = "/content", method = RequestMethod.GET)
	public CommonResult<HomeContentResult> content() {
		HomeContentResult contentResult = homeService.content();
		return CommonResult.success(contentResult);
	}
	
	@ApiOperation("根据条件分页获取商品")
	@RequestMapping(value = "/getProductList", method = RequestMethod.GET)
	public CommonResult<List<PmsProduct>> getProductList (
			@RequestParam(required = false) Long brandId,
			@RequestParam(required = false) Long categoryId,
			@RequestParam(required = false) String sortType,
			@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		List<PmsProduct> productList = homeService.getProductList(brandId, categoryId, sortType, pageSize, pageNum);
		return CommonResult.success(productList);
	}
	
	/*
	@ApiOperation("分页获取推荐商品")
	@RequestMapping(value = "/recommendProductList", method = RequestMethod.GET)
	public CommonResult<List<PmsProduct>> recommendProductList(
			@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		List<PmsProduct> productList = homeService.recommendProductList(pageSize, pageNum);
		return CommonResult.success(productList);
	}
	*/

	@ApiOperation("获取首页商品分类")
	@RequestMapping(value = "/productCateList", method = RequestMethod.GET)
	public CommonResult<List<ProductCategoryOptions>> getProductCateList() {
		List<ProductCategoryOptions> productCategoryList = homeService.getProductCateList();
		return CommonResult.success(productCategoryList);
	}
	
	/*
	@ApiOperation("根据分类获取专题")
	@RequestMapping(value = "/subjectList", method = RequestMethod.GET)
	public CommonResult<List<CmsSubject>> getSubjectList(@RequestParam(required = false) Long cateId,
			@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		List<CmsSubject> subjectList = homeService.getSubjectList(cateId, pageSize, pageNum);
		return CommonResult.success(subjectList);
	}
	*/

	@ApiOperation("首页商品详情")
	@RequestMapping(value = "/productInfo/{productId}", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult<ProductDetailResult> productInfo(@PathVariable Long productId) {
		ProductDetailResult productInfo = homeService.getProductInfo(productId);
		return CommonResult.success(productInfo);
	}

	@ApiOperation("首页商品sku信息")
	@RequestMapping(value = "/productSku/{productId}", method = RequestMethod.GET)
	public CommonResult<ProductSkuResult> productInfo(@PathVariable Long productId, @RequestParam(required = false) String sp1,
			@RequestParam(required = false) String sp2, @RequestParam(required = false) String sp3) {
		ProductSkuResult productSku = homeService.getProductSku(productId, sp1, sp2, sp3);
		return CommonResult.success(productSku);
	}

	@ApiOperation("获取会员专区商品")
	@RequestMapping(value = "/getVipProductList", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult<List<PmsProduct>> getVipProductList(){
		List<PmsProduct> vipProductList = homeService.getVipProductList();
		return CommonResult.success(vipProductList);
	}

	@ApiOperation("获取积分专区商品")
	@RequestMapping(value = "/getPointProductList", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult<List<PmsProduct>> getPointProductList(){
		List<PmsProduct> pointProductList = homeService.getPointProductList();
		return CommonResult.success(pointProductList);
	}

	@ApiOperation("获取积分兑换专区")
	@RequestMapping(value = "/getPointExchangeProductList", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult<List<PmsProduct>> getPointExchangeProductList(){
		List<PmsProduct> pointExchangeProductList = homeService.getPointExchangeProductList();
		return CommonResult.success(pointExchangeProductList);
	}



}
