package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	plantModel "sundynix-micro-go/app/plant/model"
	"sundynix-micro-go/app/plant/rpc/internal/svc"
	"sundynix-micro-go/app/plant/rpc/plant"
)

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

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

func (l *GetTopicDetailLogic) GetTopicDetail(in *plant.IdReq) (*plant.TopicInfo, error) {
	var t plantModel.Topic
	if err := l.svcCtx.DB.First(&t, "id = ?", in.Id).Error; err != nil {
		return nil, err
	}
	return &plant.TopicInfo{Id: t.ID, Name: t.Name, Icon: t.Icon, Desc: t.Desc, PostCount: int32(t.PostCount)}, nil
}
