package placement_topic

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *GetPlacementTopicLogic) GetPlacementTopic(req *types.PlacementTopicPath) (*types.PlacementTopicData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.PlacementTopic.Get(l.ctx, tenantID, uid, req.ID)
	if err != nil {
		return nil, err
	}
	data := toPlacementTopicData(*item)
	return &data, nil
}
