package com.jwipc.shopping.controller.pc;

import com.jwipc.shopping.constant.ModuleConst;
import com.jwipc.shopping.logic.OnlineMallLogic;
import com.jwipc.shopping.model.query.ShoppingDetailQuery;
import com.jwipc.shopping.model.vo.ShoppingDetailReponse;
import com.jwipc.sys.client.DictClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RequestMapping;


/**
 * 功能描述:
 *
 * @Author: zx
 * @Date: 2024/3/13 0013 16:28
 */
@Controller
@RequestMapping(ModuleConst.MODULE_ROOT + "/shopping/page")
@RequiredArgsConstructor
@Slf4j
public class ShoppingMallPageController {

    @Autowired
    DictClient dictClient;
    @Autowired
    OnlineMallLogic onlineMallLogic;

    /**
     * 各商城比价页面
     *
     * @return 页面
     */
    @RequestMapping("/compare/price/index")
    public String comparePriceIndex(Model model){
       // model.addAttribute("omList", dictClient.getDicByType("online_mall"));
        return ModuleConst.MODULE_ROOT + "/shopping/cp_index";
    }


    /**
     * 选购商品确认页面
     *
     * @param model model
     * @param parentFrameName 父级页面FrameName
     * @return 页面
     */
    @RequestMapping("/chose/buy/confirm/page")
    public String choseBuyConfirmPage(Model model, String accessToken, String parentFrameName){
        model.addAttribute("parentFrameName", parentFrameName);
        model.addAttribute("accessToken", accessToken);
        return ModuleConst.MODULE_ROOT +"/shopping/chose_buy_confirm";
    }


    /**
     * 各商城商品详情页面
     *
     * @return 页面
     */
    @RequestMapping("/cpDetail")
    public String cpDetail(Model model,String sku){
        ShoppingDetailQuery shoppingDetailQuery = new ShoppingDetailQuery();
        shoppingDetailQuery.setSku(sku);
        ShoppingDetailReponse shoppingDetail =onlineMallLogic.findShoppingDetail(shoppingDetailQuery);
        model.addAttribute("content", (shoppingDetail==null || shoppingDetail.getResult() ==null)?"":shoppingDetail.getResult().getIntroduction());
        return ModuleConst.MODULE_ROOT + "/shopping/cp_detail";
    }


    @GetMapping("/select")
    public String select() {
        return ModuleConst.MODULE_ROOT + "/shopping/selectPurchase";
    }
    @GetMapping("/selectMore")
    public String selectMore() {
        return ModuleConst.MODULE_ROOT + "/shopping/selectMorePurchase";
    }



}
