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 PublishPlacementTopicOutreachDraftLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *PublishPlacementTopicOutreachDraftLogic) PublishPlacementTopicOutreachDraft(req *types.PublishPlacementTopicOutreachDraftHandlerReq) (*types.PublishOutreachDraftData, 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.NewPublishOutreachDraftLogic(l.ctx, l.svcCtx).PublishOutreachDraft(&types.PublishOutreachDraftHandlerReq{
		BrandPath: types.BrandPath{ID: scope.BrandID},
		PublishOutreachDraftReq: types.PublishOutreachDraftReq{
			ScanPostID: req.ScanPostID,
			Text:       req.Text,
			Confirm:    req.Confirm,
		},
	})
}
