package com.caimei.www.controller.unlimited;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.content.ProductDetail;
import com.caimei.www.pojo.content.ProductList;
import com.caimei.www.pojo.content.Parameter;
import com.caimei.www.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 商品（product）
 *
 * @author : Charles
 * @date : 2020/6/12
 */
@Controller
public class ProductController extends BaseController {

	private static final String PRODUCT_LIST_PATH = "product/list";
	private static final String PRODUCT_DETAIL_PATH = "product/detail";

    private ProductService productService;
    @Autowired
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }

    /**
     * 商品分类列表/搜索结果 页面
     */
    @GetMapping("/product/list.html")
    public String list() {
        return PRODUCT_LIST_PATH;
    }

    /**
     * 商品详情页
     */
    @GetMapping("/product/detail.html")
    public String detail(final Model model, @RequestParam("id") Integer productId) {
        ProductDetail detail = productService.getProductDetailById(productId);
        model.addAttribute("product", detail);
        return PRODUCT_DETAIL_PATH;
    }

    /**
     * 详情-图片
     * @return
     */
    @GetMapping("/product/images")
    @ResponseBody
    public JsonModel<List<String>> getProductDetailImages(Integer productId) {
        return productService.getProductDetailImages(productId);
    }


    /**
     * 详情-相关推荐
     * @return
     */
    @GetMapping("/product/recommend")
    @ResponseBody
    public JsonModel<List<ProductList>> getProductDetailRecommends(Integer productId, Integer recommendType) {
        return productService.getProductDetailRecommends(productId, recommendType);
    }

    /**
     * 详情-相关参数
     * @return
     */
    @GetMapping("/product/parameter")
    @ResponseBody
    public JsonModel<List<Parameter>> getProductParameters(Integer productId) {
        return productService.getProductParameters(productId);
    }






}
