package api

import (
	"kra/internal/plugin/email/model/response"
	"kra/internal/plugin/email/service"
	pkgResponse "kra/pkg/response"

	"github.com/gin-gonic/gin"
)

type EmailApi struct{}

// EmailTest
// @Tags      System
// @Summary   发送测试邮件
// @Security  ApiKeyAuth
// @Produce   application/json
// @Success   200  {string}  string  "{"success":true,"data":{},"msg":"发送成功"}"
// @Router    /email/emailTest [post]
func (s *EmailApi) EmailTest(c *gin.Context) {
	err := service.ServiceGroupApp.EmailTest()
	if err != nil {
		pkgResponse.FailWithMessage("发送失败", c)
		return
	}
	pkgResponse.OkWithMessage("发送成功", c)
}

// SendEmail
// @Tags      System
// @Summary   发送邮件
// @Security  ApiKeyAuth
// @Produce   application/json
// @Param     data  body      response.Email  true  "发送邮件必须的参数"
// @Success   200   {string}  string                "{"success":true,"data":{},"msg":"发送成功"}"
// @Router    /email/sendEmail [post]
func (s *EmailApi) SendEmail(c *gin.Context) {
	var email response.Email
	err := c.ShouldBindJSON(&email)
	if err != nil {
		pkgResponse.FailWithMessage(err.Error(), c)
		return
	}
	err = service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body)
	if err != nil {
		pkgResponse.FailWithMessage("发送失败", c)
		return
	}
	pkgResponse.OkWithMessage("发送成功", c)
}
