package captcha

import (
	"context"

	"tyc-server/app/main/api/internal/svc"
	"tyc-server/app/main/api/internal/types"
	"tyc-server/pkg/captcha"

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

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

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

func (l *GetEncryptedSceneIdLogic) GetEncryptedSceneId() (resp *types.GetEncryptedSceneIdResp, err error) {
	cfg := l.svcCtx.Config.Captcha
	encrypted, genErr := captcha.GenerateEncryptedSceneID(cfg.SceneID, cfg.EKey, 3600)
	if genErr != nil {
		// 记录日志，返回通用错误
		l.Errorf("generate encrypted scene id error: %+v", genErr)
		return nil, genErr
	}
	return &types.GetEncryptedSceneIdResp{
		EncryptedSceneId: encrypted,
	}, nil
}
