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

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

func (l *UpdatePlacementTopicOutreachDraftLogic) UpdatePlacementTopicOutreachDraft(
	req *types.UpdatePlacementTopicOutreachDraftHandlerReq,
) (*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.NewUpdateOutreachDraftLogic(l.ctx, l.svcCtx).UpdateOutreachDraft(&types.UpdateOutreachDraftHandlerReq{
		BrandPath: types.BrandPath{ID: scope.BrandID},
		DraftID:   req.DraftID,
		UpdateOutreachDraftReq: types.UpdateOutreachDraftReq{
			DraftIndex: req.DraftIndex,
			Text:       req.Text,
		},
	})
}
