package com.wteam.controller.card;

import com.jeequan.jeepay.exception.JeepayException;
import com.wteam.framework.common.enums.CardTypeEnum;
import com.wteam.framework.common.enums.ResultUtil;
import com.wteam.framework.common.vo.ResultMessage;
import com.wteam.framework.modules.book.entity.Card;
import com.wteam.framework.modules.book.entity.dto.OrderCardReq;
import com.wteam.framework.modules.book.entity.dto.OrderReq;
import com.wteam.framework.modules.book.entity.vo.CardVo;
import com.wteam.framework.modules.book.service.CardService;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author doncic
 * @date 2023/9/18 19:18
 */
@Slf4j
@Tag(name = "卡相关接口管理")
@RestController
@RequestMapping("/v1/card")
public class CardController {


    @Autowired
    private CardService cardService;

    /**
     * 查询出该门店下的卡
     * 通过枚举来区别卡类型
     *
     * @param id           门店id
     * @param cardTypeEnum
     * @return
     */
    @Operation(summary = "展示该门店所有卡")
    @GetMapping("/{cardTypeEnum}/{id}")
    public ResultMessage<List<Card>> showCard(
            @ApiParam(value = "卡ID", required = true) @PathVariable("id") Long id,
            @PathVariable CardTypeEnum cardTypeEnum) {
        return cardService.showCard(id, cardTypeEnum);
    }


    /**
     * 查看卡的详细信息
     *
     * @return
     */
    @Operation(summary = "展示卡详细信息")
    @PostMapping("/showCardDetails/{id}")
    public ResultMessage<CardVo> showCardDetails(@ApiParam(value = "卡ID", required = true) @PathVariable("id") Long id) {
        return cardService.showCardDetails(id);
    }

//    /**
//     * 月卡和次卡的购买
//     *
//     * @param accessToken
//     * @param orderId
//     * @param cardId
//     * @return
//     */
//    @Operation(summary = "月卡和次卡购买")
//    @PostMapping("/buyCard/{accessToken}/{orderId}/{cardId}")
//    public ResultMessage<String> buyCard(
//            @PathVariable("accessToken") String accessToken,
//            @ApiParam(value = "订单ID", required = true) @PathVariable String orderId,
//            @ApiParam(value = "卡ID", required = true) @PathVariable Long cardId) {
//        return cardService.buyCard(accessToken, orderId, cardId);
//    }

//    @Operation(summary = "储值卡充值")
//    @PostMapping("/chargeCard/{accessToken}/{id}")
//    public ResultMessage chargeCard(@PathVariable("accessToken") String accessToken,
//                                    @ApiParam(value = "卡ID", required = true) @PathVariable("id") Long id) {
//        return cardService.chargeCard(accessToken, id);
//    }


    /**
     * 使用储值卡支付
     *
     * @param orderId
     * @param cardId
     * @return
     */
    @Operation(summary = "使用储值卡支付")
    @PostMapping("/valueCardPay/{orderId}/{cardId}")
    public ResultMessage valueCardPay(@PathVariable String orderId, @PathVariable Integer cardId) {
        return cardService.valueCardPay(orderId, cardId);
    }


//    /**
//     * 储值卡的充值操作
//     *
//     * @return
//     */
//    @Operation(summary = "储值卡充值")
//    @PostMapping("/cardCharge/{cardId}/{orderId}")
//    public ResultMessage cardCharge(@PathVariable String orderId, @PathVariable Integer cardId) {
//        return cardService.cardCharge(orderId, cardId);
//    }


    /**
     * 获得月卡对应的二维码信息
     *
     * @param cardId
     * @return
     */
    //TODO ：这个改为使用该卡的购买id查询其对应的二维码
    @Operation(summary = "获得月卡对应的二维码")
    @PostMapping("/getQrCodeByCard/{cardId}")
    public ResultMessage getQrCodeByCard(@PathVariable String cardId) {
        return cardService.getQrCodeByCard(cardId);
    }


    @Operation(summary = "提交卡购买订单")
    @PostMapping("/generateCardOrder/{accessToken}")
    public ResultMessage generateCardOrder(@PathVariable("accessToken") String accessToken,
                                           @ApiParam(value = "订单参数", required = true) @RequestBody OrderCardReq orderCardReq) {
        return cardService.generateCardOrder(accessToken, orderCardReq);

    }

    @Operation(summary = "提交充值卡订单信息")
    @PostMapping("/getQrCodeByCard/{accessToken}")
    public ResultMessage getChargeCardOrder(@PathVariable("accessToken") String accessToken,
                                            @ApiParam(value = "卡id", required = true) @PathVariable Integer cardId,
                                            @RequestParam Double currentBalance) {
        return cardService.getChargeCardOrder(accessToken, cardId, currentBalance);
    }

}
