package ai

import (
	"context"

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

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

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

func (l *ListAIProvidersLogic) ListAIProviders() (*types.AIProvidersData, error) {
	options := l.svcCtx.AI.ListProviders(l.ctx)
	items := make([]types.AIProviderOption, 0, len(options))
	for _, option := range options {
		items = append(items, types.AIProviderOption{
			ID:      option.ID,
			Label:   option.Label,
			Streams: option.Streams,
		})
	}
	return &types.AIProvidersData{Providers: items}, nil
}
