package com.seer.teach.mp.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.common.response.OssImageUploadResp;
import com.seer.teach.mp.api.request.GetQrCodeReq;
import com.seer.teach.mp.app.controller.req.MpGenerateQrCodeReq;
import com.seer.teach.mp.app.controller.resp.MpQrCodeResp;
import com.seer.teach.mp.app.service.AppOfficialQrCodeService;
import com.seer.teach.mp.service.IWechatMiniProgramService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;

@EncryptionAnnotation
@DecryptionAnnotation
@Tag(name = "APP - 微信二维码")
@RestController
@RequestMapping("/app/qrcode")
@LogPrint
@RequiredArgsConstructor
public class AppMpQrCodeController {

    private final AppOfficialQrCodeService appOfficialQrCodeService;

    private final IWechatMiniProgramService wechatMiniProgramService;

    /**
     * 生成微信服务号二维码
     */
    @Operation(summary = "生成微信服务号二维码")
    @PostMapping("/official/generate")
    @SaCheckPermission("mp:app:qrcode:generate")
    public ResultBean<MpQrCodeResp> generateOfficialQrCode(@Valid @RequestBody MpGenerateQrCodeReq req) {
        return ResultBean.success(appOfficialQrCodeService.generateQrCode(req));
    }


    /**
     * 生成微信小程序二维码
     */
    @Operation(summary = "生成微信小程序二维码")
    @PostMapping("/mini/generate")
    @SaCheckPermission("mp:app:qrcode:mini-generate")
    public ResultBean<String> generateQrCode(@Valid @RequestBody GetQrCodeReq reqParams) {
        OssImageUploadResp resp = wechatMiniProgramService.createQrcode(reqParams);
        return ResultBean.success(resp.getUrl());
    }
}