import { NextMessageRequest as ApiNextMessageRequest } from '@spiffy-ai/commerce-api-client';
import { NextMessageRequest } from '../models';
import { coreUserEventToApiUserEvent } from './coreUserEventToApiUserEvent';

export const messageRequestToCommerceMessageRequest = (
  data: NextMessageRequest,
): ApiNextMessageRequest => ({
  context: {
    chat_id: data.context.chatId,
    org_id: data.context.orgId,
    org_short_name: data.context.orgShortName,
    user_id: data.context.userId,
    source: data.context.source,
    env: data.context.env,
  },
  id: data.id,
  feature_flags: data.featureFlags,
  override_config_version: data.overrideConfigVersion,
  override_model_datetime: data.overrideModelDatetime,
  user_events: data.userEvents?.map(userEvent => coreUserEventToApiUserEvent(userEvent)),
  generation_params: {
    model: data.generationParams?.model,
    max_tokens: data.generationParams?.maxTokens,
    stop: data.generationParams?.stop,
    stream: data.generationParams?.stream,
    temperature: data.generationParams?.temperature,
    top_p: data.generationParams?.topP,
    num_suggestions: data.generationParams?.numSuggestions,
    response_system_prompt: data.generationParams?.responseSystemPrompt,
    suggestion_system_prompt: data.generationParams?.suggestionSystemPrompt,
    response_caching: data.generationParams?.responseCaching,
  },
});
