package ai

import (
	"context"

	libprompt "haixun-backend/internal/library/prompt"
	domai "haixun-backend/internal/model/ai/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type ChatStreamLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewChatStreamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatStreamLogic {
	return &ChatStreamLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *ChatStreamLogic) ChatStream(req *types.AIChatReq, token string) (<-chan domai.StreamEvent, error) {
	system, err := libprompt.AIChatSystem(req.System)
	if err != nil {
		return nil, err
	}
	return l.svcCtx.AI.StreamText(l.ctx, toGenerateRequest(req, token, system))
}
