package com.tzy.controller.appuser;

import com.tzy.common.config.handle.ApiVersion;
import com.tzy.common.constant.MsgConstants;
import com.tzy.common.dto.OutDTO;
import com.tzy.common.dto.UserInfo;
import com.tzy.common.exception.AppAssert;
import com.tzy.common.utils.UserUtils;
import com.tzy.dto.UserPayNoticeDTO;
import com.tzy.sportcard.group.service.ICardGroupOrderInfoService;
import com.tzy.sportcard.message.service.IAppMsgRecordService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(value = "用户提示")
@RestController
@RequestMapping("/api/{version}/recommend")
@Slf4j
public class RecommendController {

    @Resource
    private ICardGroupOrderInfoService orderService;
    @Resource
    private IAppMsgRecordService msgRecordService;

    /**
     * 下单前消费金额提示
     */
    @ApiVersion(1.0)
    @PostMapping(value = "/order")
    @ResponseBody
    public OutDTO preOrderRecommend() {
        UserInfo userInfo = UserUtils.getSimpleUserInfo(true);
        AppAssert.notNull(userInfo, MsgConstants.NEED_LOGIN);
        UserPayNoticeDTO notice = orderService.preOrderRecommendAmount(userInfo.getId());
        if(notice.isNoticeFlag()){
            msgRecordService.addRecord(userInfo.getId(),notice);
        }
        return OutDTO.ok().put("notice", notice);
    }

    /**
     * 下单前消费金额提示
     */
    @ApiVersion(2.0)
    @PostMapping(value = "/order")
    public OutDTO preOrderRecommend2() {
        UserInfo userInfo = UserUtils.getSimpleUserInfo(true);
        AppAssert.notNull(userInfo, MsgConstants.NEED_LOGIN);
        UserPayNoticeDTO notice = orderService.preOrderRecommendAmount2(userInfo.getId());
        if(notice.isNoticeFlag()){
            msgRecordService.addRecord(userInfo.getId(),notice);
        }
        return OutDTO.ok().put("notice", notice);
    }
}
