package com.guwan.controller.login;

import com.github.hui.quick.plugin.qrcode.wrapper.QrCodeGenWrapper;
import com.guwan.common.R;
import com.guwan.domain.MockScan;
import com.guwan.service.MockScanService;
import com.guwan.util.ConvertBase64Util;
import com.guwan.util.UUIDUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Path;

@RestController
@RequestMapping("/easyScan")
public class EasyScanController {

    @Resource
    MockScanService mockScanService;

    @GetMapping("/11")
    public R QrCode(String content) {
        BufferedImage image = null;
        try {
            image = QrCodeGenWrapper.of(content).asBufferedImage();
            Path file = new File("qrcode.png").toPath();
            ImageIO.write(image, "png", file.toFile());
        } catch (Exception e) {
            e.printStackTrace();
        }
        mockScanService.save(new MockScan(ConvertBase64Util.imageToString(image), UUIDUtil.uuid()));

        return R.ok().put("data", ConvertBase64Util.imageToString(image)).put("uuid", UUIDUtil.uuid());
    }

    @GetMapping("/no")
    public R QrCodeBySearch() {
        BufferedImage image = null;

        String content = null;
        //查询封装成content
       // content = ();

        try {
            image = QrCodeGenWrapper.of(content).asBufferedImage();
            Path file = new File("qrcode.png").toPath();
            ImageIO.write(image, "png", file.toFile());
        } catch (Exception e) {
            e.printStackTrace();
        }
        mockScanService.save(new MockScan(ConvertBase64Util.imageToString(image), UUIDUtil.uuid()));

        return R.ok().put("data", ConvertBase64Util.imageToString(image)).put("uuid", UUIDUtil.uuid());
    }




}
