import { CustomHttpResponseOptions , KibanaResponseFactory } from 'src/core/server' ; /**
 * Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
 * We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
 * TODO: Once more types are moved into kbn package we can move this into a kbn package.
 */ const statusToErrorMessage = ( statusCode ) : 'Bad Request' | 'Unauthorized' | 'Forbidden' | 'Not Found' | 'Conflict' | 'Internal Error' | '(unknown error)' => { switch ( statusCode ) { case 400 : return 'Bad Request' ; case 401 : return 'Unauthorized' ; case 403 : return 'Forbidden' ; case 404 : return 'Not Found' ; case 409 : return 'Conflict' ; case 500 : return 'Internal Error' ; default : return '(unknown error)' ; } } ; /**
 * Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
 * We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
 * TODO: Once more types are moved into kbn package we can move this into a kbn package.
 */ export class SiemResponseFactory { constructor ( private response ) { } error < T > ( { statusCode , body , headers } ) { const contentType = { 'content-type' : 'application/json' , } ; const defaultedHeaders = { ... contentType , ... ( headers ?? { } ) , } ; return this . response . custom ( { body : Buffer . from ( JSON . stringify ( { message : body ?? statusToErrorMessage ( statusCode ) , status_code : statusCode , } ) ) , headers : defaultedHeaders , statusCode , } ) ; } } /**
 * Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
 * We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
 * TODO: Once more types are moved into kbn package we can move this into a kbn package.
 */ export const buildSiemResponse = ( response ) : SiemResponseFactory => new SiemResponseFactory ( response ) ;