import type { Adapter, CanHandle, ParseRequest, BuildResponse } from '../types';

const target = 'Simple JSON (default)';

const canHandle: CanHandle = (request) => {
  const { intent } = request;
  return !!intent;
};

const parseRequest: ParseRequest = (request) => {
  const { intent, parameters, user, queryText, sessionId, locale = 'en-US' } = request;
  return {
    orginalRequest: request,
    intent,
    parameters: parameters || {},
    target,
    locale,
    user,
    queryText,
    sessionId,
  };
};

const buildResponse: BuildResponse = (conversation) => ({
  ...conversation.response,
});

const SimpleJSON: Adapter = {
  target,
  canHandle,
  parseRequest,
  buildResponse,
};

export { SimpleJSON };

{'avg_line_length': 20.02777777777778, 'max_line_length': 87, 'alphanum_fraction': 0.6546463245492372, 'licenses': ['MIT'], 'repository_name': 'andrelandgraf/react-ssml-dom', 'path': 'packages/ssml-dom/src/conversation/adapters/simple-json.ts', 'size': 721, 'lang': 'TypeScript'}