package com.greenorange.promotion.controller.wechat;


import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.config.WxAccessToken;
import com.greenorange.promotion.model.dto.CommonRequest;
import com.greenorange.promotion.model.dto.CommonStringRequest;
import com.greenorange.promotion.model.enums.UserRoleEnum;
import com.greenorange.promotion.service.wechat.WechatGetQrcodeService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.*;


@Slf4j
@RestController
@Tag(name = "获取二维码模块")
@RequestMapping("/qrcode")
@Transactional
public class WechatGetQrcodeController {



    @Resource
    private RedisTemplate<String, Object> redisTemplate;


    @Resource
    private WechatGetQrcodeService wechatGetQrcodeService;



    /**
     * (小程序端)获取接口调用凭据
     */
    @Hidden
    @GetMapping("/get/token")
    @Operation(summary = "(小程序端)获取接口调用凭据", description = "参数：无, 权限：所有人, 方法名：getAccessToken")
    public BaseResponse<WxAccessToken> getAccessToken() {
        WxAccessToken wxAccessToken = wechatGetQrcodeService.getApiAccessToken();
        return ResultUtils.success(wxAccessToken);
    }


    /**
     * 微信小程序获取二维码
     * @return
     * @throws IOException
     */
    @PostMapping("/get/qrcode")
    @Operation(summary = "微信小程序获取二维码", description = "参数：无, 权限：所有人, 方法名：getQrcode")
//    @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
    public BaseResponse<String> getQrcode(@Valid @RequestBody CommonStringRequest commonStringRequest) throws IOException {
        String inviteCode = commonStringRequest.getTemplateString();
        String view = wechatGetQrcodeService.getWxQrCode(inviteCode, UserRoleEnum.SUPERVISOR);
        return ResultUtils.success(view);
    }


//    /**
//     * 微信小程序获取课程码
//     * @return
//     * @throws IOException
//     */
//    @Hidden
//    @PostMapping("/get/course/qrcode")
//    @Operation(summary = "微信小程序获取课程码", description = "参数：无, 权限：所有人, 方法名：getCourseQrcode")
////    @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
//    public BaseResponse<String> getCourseQrcode(@Valid @RequestBody CommonRequest commonRequest, HttpServletRequest request) throws Exception {
//        String view = wechatGetQrcodeService.getWxCourseQrCode(commonRequest, request);
//        return ResultUtils.success(view);
//    }









}
