package usecase

import (
	"context"

	"haixun-backend/internal/model/ai/domain/enum"
)

type Message struct {
	Role    string
	Content string
}

type Credential struct {
	APIKey string
}

type GenerateRequest struct {
	Provider    enum.ProviderID
	Model       string
	Credential  Credential
	System      string
	Messages    []Message
	Temperature *float64
	MaxTokens   *int
}

type GenerateResult struct {
	Text         string
	FinishReason string
}

type StreamEvent struct {
	Type         string `json:"type"`
	Text         string `json:"text,omitempty"`
	FinishReason string `json:"finish_reason,omitempty"`
	Error        string `json:"error,omitempty"`
}

type ProviderOption struct {
	ID      string
	Label   string
	Streams bool
}

type ProviderModels struct {
	ID      string
	Label   string
	Models  []string
	Streams bool
	Error   string
}

type Provider interface {
	ID() enum.ProviderID
	ListModels(ctx context.Context, credential Credential) ([]string, error)
	GenerateText(ctx context.Context, req GenerateRequest) (*GenerateResult, error)
	StreamText(ctx context.Context, req GenerateRequest) (<-chan StreamEvent, error)
}

type UseCase interface {
	ListProviders(ctx context.Context) []ProviderOption
	ListProviderModels(ctx context.Context, provider enum.ProviderID, credential Credential) ProviderModels
	GenerateText(ctx context.Context, req GenerateRequest) (*GenerateResult, error)
	StreamText(ctx context.Context, req GenerateRequest) (<-chan StreamEvent, error)
}
