package com.cirle.scientific.controller.brandProduct;


import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.BrandProductService;
import com.cirle.scientific.utils.DeviceUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/brand")
@Api("品牌专区相关接口")
public class BrandProductController {

    @Autowired
    private BrandProductService brandProductService;

    @GetMapping("/detail")
    @ApiOperation("跳转详情页")
    public String detail(
            @ApiParam(name = "from", value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from", required = true) String from,
            @RequestParam(value = "productId") Long productId,
            HttpServletRequest request
    ) {
        request.setAttribute("productId", productId);
        boolean isM = DeviceUtil.isMobileDevice(request);
        if (isM) {
            return "html5/prefecture/prefecture";
        } else {
            return "web/brand/brand";
        }
//
//        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
//            return "html5/prefecture/prefecture";
//        } else if (StringUtils.isNotBlank(from) && from.equals("web")) {
//            return "web/brand/brand";
//        } else {
//            return "";
//        }
    }
    @GetMapping("/upload")
    @ApiOperation("跳转课件上传页")
    public String upload(
            @ApiParam(name = "from", value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from", required = true) String from,
            @RequestParam(value = "productId") Long productId,
            HttpServletRequest request
    ) {
        request.setAttribute("productId", productId);
        boolean isM = DeviceUtil.isMobileDevice(request);
        if (isM) {
            return "html5/prefecture/upload";
        } else {
            return "web/brand/upload";
        }
    }

    @PostMapping("/getDetailData")
    @ApiOperation("详情接口数据")
    @ResponseBody
    public Result getDetailData(
            @RequestParam(value = "productId") Long productId
    ) {
        return brandProductService.getDetailData(productId);

    }

}
