// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package topic

import (
	"context"

	"sundynix-micro-go/app/plant/api/internal/svc"
	"sundynix-micro-go/app/plant/api/internal/types"
	"sundynix-micro-go/app/plant/rpc/plant"

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

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

// 创建话题
func NewCreateTopicLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTopicLogic {
	return &CreateTopicLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateTopicLogic) CreateTopic(req *types.TopicReq) error {
	name := req.Name
	if name == "" {
		name = req.Title
	}
	_, err := l.svcCtx.PlantRpc.CreateTopic(l.ctx, &plant.CreateTopicReq{
		Name: name, Icon: req.Icon, Desc: req.Desc,
		Title: req.Title, Remark: req.Remark, StartTime: req.StartTime, EndTime: req.EndTime,
	})
	return err
}
