package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;

import cn.cslg.report.common.utils.Response;
import cn.cslg.report.common.utils.message.MessageUtils;
import cn.cslg.report.entity.Template;
import cn.cslg.report.service.business.TemplateService;
import cn.hutool.extra.mail.MailUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "报告模板")
@RestController
@RequestMapping(Constants.REPORT_API + "/template")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@SuppressWarnings({"all"})
public class TempleController {
    public final TemplateService templateService;
    public final MessageUtils mailUtils;
    @RequestMapping(value = "/getTemplateByType", method = RequestMethod.POST)
    @Operation(summary = "根据报告类型获得模板")
    public  String getTemplateByType(@RequestBody Template template) throws IOException{
        return templateService.getTemplateByType(template);
    }
    @RequestMapping(value = "/sendEmail", method = RequestMethod.GET)
    @Operation(summary = "发送邮箱")
    public  String sendEmail() throws IOException{
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("title", "任务通知");
        map.put("template", "mail/Synery.html");

        map.put("value1", "personName");
        map.put("email", "2232623707@qq.com");
        map.put("img", "\\src\\main\\resources\\mail\\logo.png");
        map.put("value2", "syneryCode.getCode()");
        map.put("value3", "url + /identificationCode");
        mailUtils.sendEmailMessage(map);
        Map<String, Object> map2 = new LinkedHashMap<>();
        map2.put("title", "任务通知");
        map2.put("template", "mail/Synery.html");

        map2.put("value1", "personName");
        map2.put("email", "1619977931@qq.com");
        map2.put("img", "\\src\\main\\resources\\mail\\logo.png");
        map2.put("value2", "syneryCode.getCode()");
        map2.put("value3", "url + /identificationCode");
        mailUtils.sendEmailMessage(map2);
        return Response.success();
    }


}
