package whatsapp

import (
	"context"
	"github.com/zeromicro/go-zero/core/errorx"
	"wechat-api/hook/aliyun"

	"wechat-api/internal/svc"
	"wechat-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemoveWhatsappTemplateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRemoveWhatsappTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveWhatsappTemplateLogic {
	return &RemoveWhatsappTemplateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx}
}

func (l *RemoveWhatsappTemplateLogic) RemoveWhatsappTemplate(req *types.RemoveTemplateReq) (*types.BaseDataInfo, error) {
	resp := types.BaseDataInfo{}

	if req.TemplateType == "" && req.TemplateCode == "" && req.TemplateName == "" && req.Language == "" {
		return nil, errorx.NewInvalidArgumentError("参数错误")
	}

	result, err := aliyun.DeleteChatappTemplate(req.TemplateName, req.Language, req.TemplateType, req.TemplateCode)
	l.Logger.Infof("result=%v err=%v\n", result, err)

	if err != nil {
		resp.Msg = err.Error()
		resp.Code = 1
	} else if *result.Body.Code == "OK" {
		resp.Data = "success"
	}

	return &resp, nil
}
