package com.cyksj.web.controller.vip;

import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.model.response.VipUserPageResp;
import com.cyksj.model.views.VipGoodsSkuFrontView;
import com.cyksj.service.vip.VipFrontService;
import com.cyksj.web.util.StpUserUtil;
import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.util.MapUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * server/银河会员
 * 项目名: yhlxj2
 * 文件名: VipController
 * 创建者: JavaZou
 * 创建时间:2025/5/14 17:52
 */
@RestController
@RequestMapping("/applet/vip")
@RequiredArgsConstructor
@Slf4j
public class VipController {

	private final BeanSearcher beanSearcher;

	private final HttpServletRequest request;

	private final VipFrontService vipFrontService;

	/**
	 * 会员信息
	 */
	@GetMapping("/get/info")
	public Result<VipUserPageResp> getVipInfo(@RequestParam(defaultValue = "1") Integer months) {
		Long userId = StpUserUtil.getUserIdAfterLogin();
		VipUserPageResp vipUserPageResp = new VipUserPageResp();
		vipUserPageResp.setMonths(months);
		//填充会员信息
		vipFrontService.fillVipInfo(userId, vipUserPageResp);
		List<VipGoodsSkuFrontView> vipGoodsSkuFrontViews = beanSearcher.searchAll(VipGoodsSkuFrontView.class, MapUtils.flatBuilder(request.getParameterMap()).orderBy(VipGoodsSkuFrontView::getGoodsId).build());
		vipUserPageResp.setSkus(vipGoodsSkuFrontViews);
		return GatewayResponse.SUCCESS.newBuilder().toResult(vipUserPageResp);
	}
}
