package elevenlabs

import (
	"context"
	"fmt"
)

// TextToSpeech generates speech from text using the default output format.
// Returns raw audio bytes (MP3 by default).
func (c *Client) TextToSpeech(ctx context.Context, voiceID string, req TextToSpeechRequest) ([]byte, error) {
	return c.TextToSpeechWithFormat(ctx, voiceID, req, DefaultOutputFormat)
}

// TextToSpeechWithFormat generates speech from text with a specific output format.
// Returns raw audio bytes in the requested format.
func (c *Client) TextToSpeechWithFormat(ctx context.Context, voiceID string, req TextToSpeechRequest, format OutputFormat) ([]byte, error) {
	if voiceID == "" {
		return nil, fmt.Errorf("%w: voice ID is required", ErrInvalidConfig)
	}
	if req.Text == "" {
		return nil, fmt.Errorf("%w: text is required", ErrInvalidConfig)
	}

	// Set default model if not specified
	if req.ModelID == "" {
		req.ModelID = DefaultModel
	}

	path := fmt.Sprintf("/text-to-speech/%s", voiceID)
	return c.doRequestRaw(ctx, "POST", path, req, format)
}
