package placement_topic

import (
	"context"

	brandlogic "haixun-backend/internal/logic/brand"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *GeneratePlacementTopicOutreachDraftsLogic) GeneratePlacementTopicOutreachDrafts(req *types.GeneratePlacementTopicOutreachDraftsHandlerReq) (*types.GenerateOutreachDraftsData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	scope, err := resolveScope(l.ctx, l.svcCtx, tenantID, uid, req.ID)
	if err != nil {
		return nil, err
	}
	return brandlogic.NewGenerateOutreachDraftsLogic(l.ctx, l.svcCtx).GenerateOutreachDrafts(&types.GenerateOutreachDraftsHandlerReq{
		BrandPath: types.BrandPath{ID: scope.BrandID},
		GenerateOutreachDraftsReq: types.GenerateOutreachDraftsReq{
			ScanPostID:     req.ScanPostID,
			TopicID:        scope.TopicID,
			Count:          req.Count,
			VoicePersonaID: req.VoicePersonaID,
			ProductID:      scope.Topic.ProductID,
		},
	})
}
