package com.hzs.system.home.controller.api;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.system.home.HoProductDetails;
import com.hzs.system.home.param.HoProductDetailsParam;
import com.hzs.system.home.service.IHoProductDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 商品简介详情配置 前端控制器
 * </p>
 *
 * @author zhangjing
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/api/ho-product-details")
@Slf4j
public class ApiHoProductDetailsController extends BaseController {

    @Autowired
    private IHoProductDetailsService hoLeaderTitleService;

    /**
     * @description: 商品简介详情配置
     * @author: zhang jing
     * @date: 2022/10/8 15:09
     * @param: [type]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @GetMapping("/getHoProductDetails/{pkAreaClassify}")
    public AjaxResult getHoProductDetails(@PathVariable Integer pkAreaClassify) {
        HoProductDetailsParam hoProductDetailsParam = hoLeaderTitleService.queryProductDetails(pkAreaClassify);
        return AjaxResult.success(hoProductDetailsParam);
    }

    /**
     * @description: 查询全部商品简介详情配置（H5页面专用）
     * @author: zhang jing
     * @date: 2023/9/10 20:54
     * @param: []
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @GetMapping("/getHoProductDetails-move")
    public AjaxResult getHoProductDetailsMove() {
        HoProductDetailsParam hoProductDetails = new HoProductDetailsParam();
        List<HoProductDetailsParam> list = hoLeaderTitleService.selectBelowProductDetailsList(hoProductDetails);
        if (CollectionUtil.isNotEmpty(list)) {
            for (HoProductDetailsParam ho : list) {
                List<HoProductDetailsParam> hoProductDetailsParam = hoLeaderTitleService.queryProductDetailsMove(ho.getPkId().intValue());
                ho.setProductDetailsList(hoProductDetailsParam);
            }
        }
        return AjaxResult.success(list);
    }

    /**
     * @description: 商品展示下拉框
     * @author: zhang jing
     * @date: 2023/4/4 18:17
     * @param: [hoLeaderTitle]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @GetMapping("/product-type")
    public AjaxResult productType(HoProductDetailsParam hoProductDetailsParam) {
        List<HoProductDetailsParam> list = hoLeaderTitleService.selectBelowProductDetailsList(hoProductDetailsParam);
        return AjaxResult.success(list);
    }

    /**
     * @description: 商品详情
     * @author: zhang jing
     * @date: 2023/6/12 14:06
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @GetMapping("/getHoWaresDetails/{pkId}")
    public AjaxResult getHoWaresDetails(@PathVariable Integer pkId) {
        QueryWrapper<HoProductDetails> queryWrapper = new QueryWrapper();
        queryWrapper.eq("PK_ID", pkId);
        HoProductDetails hoProductDetails = hoLeaderTitleService.getOne(queryWrapper);
        return AjaxResult.success(hoProductDetails);
    }


}
